સ્ટેટ ક્યાં રહે છે તે નક્કી કરવું એ સૌથી મહત્વપૂર્ણ આર્કિટેક્ચર કૌશલ્યમાંથી એક છે. માર્ગદર્શક સિદ્ધાંત: દરેક સ્ટેટ પીસ સૌથી સાંકડા સ્કોપ માં મૂકો જે હજુ પણ તે જરૂર હોય તેવા બધાને સંતોષ આપે છે — અને દરેક પ્રકારની સ્ટેટને સાચા ટૂલ સાથે મેચ કરો.
નિર્ણય ફ્રેમવર્ક
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
