স্টেট কোথায় থাকে তা সিদ্ধান্ত নেওয়া সবচেয়ে গুরুত্বপূর্ণ আর্কিটেকচার দক্ষতাগুলির মধ্যে একটি। নির্দেশনামূলক নীতি: প্রতিটি স্টেটের অংশকে সবচেয়ে সংকীর্ণ স্কোপে রাখুন যা এখনও সবাইকে সন্তুষ্ট করে যারা এটি প্রয়োজন — এবং প্রতিটি ধরনের স্টেটকে সঠিক সরঞ্জামের সাথে মেলান।
সিদ্ধান্তের কাঠামো
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
