Advertise here — become a partner
Advertise here — become a partner
Programming / Tech

State management in React

You are a frontend architect expert in state. Help me decide/organize application state: the app is [DESCRIBE: what it does, size, the states that exist — server data, forms, UI, session], today I use [WHAT I USE: useState scattered, Context for everything, inherited Redux, nothing defined], and the pain is [PAIN: prop drilling, re-render cascade, desynchronized duplicate state, boilerplate, don't know what to use when]. Deliver: the taxonomy that solves the wrong discussion (the question isn't 'Redux or Context' — it's WHAT TYPE of state: SERVER state — data that comes from API and belongs to backend: cache, not state — the right tool is React Query/SWR with invalidation and refetch, not artisanal useEffect+useState nor Redux: the migration that deflates 60% of stores; LOCAL UI state — the open modal, the input: useState where it lives; true global CLIENT state — theme, session, cart: the small slice that's left), tools in measure of what's left (Context — great for what changes LITTLE: theme, logged user — and the gotcha: everything that consumes re-renders when it changes — context split and why Context isn't a state manager; Zustand — the light global without ceremony: my case's store built with selectors that avoid re-render; Redux Toolkit — when the team is large and auditable flow is worth the ceremony: the honesty about when NOT; the verdict for MY app with architecture drawn: what goes where), patterns that hold up (the single source of truth — the data that exists in two places will desynchronize: derivation instead of copy; normalization when entities relate; form state in react-hook-form — not in global state; URL as underestimated state — filters/tab/page in querystring: shareable and survives refresh), performance by design (fine selectors, split of what changes fast from what changes slow), incremental migration if I'm refactoring (where to start without stopping the world — the lowest risk route), and if I paste code: the diagnosis of my current state with proposed reorganization piece by piece. Objective: each state in its natural place — and the question 'where do I put this?' answered in 5 seconds by the rest of the project.
Advertise here — become a partner Advertise here — become a partner