స్థితి ఎక్కడ ఉందో నిర్ణయించడం అత్యంత ముఖ్యమైన ఆర్కిటెక్చర్ నైపుణ్యాలలో ఒకటి. నిర్దేశక సూత్రం: ప్రతిটి స్థితి భాగాన్ని ఇరుకైన పరిధిలో ఉంచండి, ఇది ఈ విషయాన్ని కావలసిన అందరినీ సంతృప్తిపరిస్తుంది — మరియు ప్రతిটి రకమైన స్థితిని సరైన సాధనంతో సరిపోల్చండి.
నిర్ణయ ఫ్రేమ్వర్క్
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
