State Management
Maybern separates server state (API data) from client state using appropriate tools for each.State Categories
| Category | Tool | Examples |
|---|---|---|
| Server State | TanStack Query | API data, entities, lists |
| Global Client State | React Context | Auth, customer, theme |
| Local Client State | useState/useReducer | Form state, UI state |
| URL State | React Router | Filters, pagination, selections |
TanStack Query (Server State)
Fetching Data
Mutations
Query Keys
Generated queries use consistent keys:React Context (Global State)
Auth Context
Customer Context
Local State
Component State
Complex Local State
URL State
Best Practices
Prefer Server State
Prefer Server State
Use TanStack Query for anything from the API. Let it handle caching, deduplication, and background updates.
URL for Shareable State
URL for Shareable State
Context for Truly Global
Context for Truly Global
Only use Context for truly global state (auth, theme). Don’t overuse it.
Local State for UI
Local State for UI
Use useState for local UI state that doesn’t need to be shared.