ਟੂਲ ਨੂੰ state ਦੀ ਕਿਸਮ ਨਾਲ ਮਿਲਾਓ, ਬਜਾਏ ਇਸ ਦੇ ਕਿ ਡਿਫੋਲਟ ਰੂਪ ਵਿੱਚ global store ਵਲ ਜਾਓ। ਬਹੁਤੇ "global state" ਦੀਆਂ ਸਮੱਸਿਆਵਾਂ ਅਸਲ ਵਿੱਚ ਕੰਮ ਲਈ ਗਲਤ ਟੂਲ ਹਨ।
ਫ਼ੈਸਲਾ ਲੈਣ ਲਈ ਗਾਈਡ
text
Local UI state (toggle, input) → useState / useReducer
Shared, low-frequency (theme, user) → Context
Server/API data → React Query / SWR (NOT a global store)
Complex global client state → Zustand / Jotai / Redux Toolkit
URL-shareable state (filters, page) → the URL (search params)
ਸਭ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਸਮਝ: server state ≠ client state
API ਤੋਂ ਡੇਟਾ ਦੂਰ ਸਥਿਤ ਡੇਟਾ ਦਾ ਹੈ, state ਜਾਂ ਜੋ ਤੁਸੀਂ ਮਾਲਕ ਹੋ। ਇਸਨੂੰ Redux ਵਿੱਚ ਰੱਖਣਾ ਮਤਲਬ ਤੁਸੀਂ manually loading, caching, refetching ਅਤੇ invalidation ਨੂੰ ਸੰਭਾਲਦੇ ਹੋ — ਦਰਦਨਾਕ ਅਤੇ ਗ਼ਲਤੀ ਲਈ ਜੋਖਮ ਵਿੱਚ। ਇੱਕ server-state library ਇਹ ਸਭ ਕਰਦੀ ਹੈ:
