4 ms·
In React: - Provided it is not an offline-first app, move as much state handling as possible out of the frontend - use SWR or React Query for server state -
by gherkinnn 4y ago
In React:
- Provided it is not an offline-first app, move as much state handling as possible out of the frontend
- use SWR or React Query for server state
- Keep pagination, filters, and other such options in your URL
- Hold state as local as possible. Only ever move state up if two or more branches of the tree need to be synchronised.
- Pass information down through props. That is what they are for. A little “prop drilling” is fine.
- Use CSS custom properties for theming
This gets you >95% of the way with very little complexity.
For the leftover pieces of global state like ‘isSidebarVisible’ I like Zustand because it is tiny both in bytes and concept.
I don’t like to use Context for state management because it litters the top-level with providers and causes unnecessary rerenders.
Avoid a single global store at all costs.