कहाँ state रहन्छ भनी निर्णय गर्नु सबैभन्दा महत्त्वपूर्ण आर्किटेक्चर कौशलहरूमध्ये एक हो। मार्गदर्शक सिद्धान्त: प्रत्येक state को टुक्रालाई सबैभन्दा साँघुरो स्कोप मा राख्नुहोस् जसले अझै पनि सबै चाहिनेलाई सन्तुष्ट गर्छ — र प्रत्येक किसिम को state लाई सही उपकरणसँग मेल खाइ दिनुहोस्।
निर्णय ढाँचा
1. Who needs this state?
- One component → local state (useState)
- A few related components → lift to common parent / small context
- Many distant components → global store or context
2. What KIND of state is it?
- Server/remote data → server-state library (React Query/SWR)
- UI/client state → useState / Zustand / Redux
- URL-derivable (filters, page) → the URL (searchParams)
- Form input → form library or local state
3. How OFTEN does it change?
- Rarely, widely shared (theme) → Context is fine
- Frequently, widely shared → store with selective subscriptions
