State architecture: local, shared, server, and external state
Large React applications become easier to design when you stop asking “Which state library should we use?” and first ask:
What kind of state is this, who owns it, what lifetime should it have, and what subscription model does it need?
Tool choice comes after classification.
The main categories
These categories can meet at boundaries, but they lead to better architecture than putting every value into one universal store.
1. Local UI state
Examples include accordion open/closed, selected tab, input draft, tooltip visibility, local sorting, and wizard steps.
const [open, setOpen] = useState(false);
Keep state local until another owner genuinely needs to coordinate with it.
2. Shared client state
Shared client state is React/application-owned data that several components must coordinate around, such as a cart draft, selected project, editor model, preferences, or a multi-step client workflow.
Possible tools include lifted useState, useReducer, Context, reducer + Context, or an external store.
Choose based on scope, update complexity, frequency, and subscriber needs—not library popularity.
3. Server state
Server state originates outside the client and represents remote authoritative data such as products, invoices, inventory, search results, profiles, and order status.
Context can transport server data, but Context is not a server cache strategy. Framework data APIs and server-state libraries solve a different lifecycle problem.
4. URL/navigation state
Some state belongs in the URL because it should survive refresh, support copy/paste links, and participate in browser navigation.
/search?q=react&page=2
/products?category=lights&sort=price
/dashboard/projects/42
The examples are literal URLs, so text is the most useful representation here.
Good candidates include search queries, page numbers, filters, selected resource IDs, and tabs that have navigation semantics.
Do not mirror URL state into local React state unless you intentionally need a second editing/draft lifecycle.
5. External store state
An external store owns data outside useState/useReducer in the component tree.
Examples include custom store objects, browser subscription APIs, third-party state libraries, or data shared with non-React code.
React provides useSyncExternalStore to integrate that source safely with rendering.
An external store can still be scoped to one feature instance.
6. Derived state
Derived values can be calculated from existing inputs:
const completed = tasks.filter(task => task.done).length;
Do not create a second state owner when a value is completely determined by another source.
Classifying one screen
An ecommerce page can contain several state categories at once.
The fact that values appear on the same page does not mean they should share one owner.
The source-of-truth question
For every value, ask where the authoritative version lives.
Many state bugs are really multiple competing sources of truth.
State lifetime
A modal open flag usually should not outlive the feature. A URL filter may need to survive remounts. A store used by non-React code may need to live independently of any React root.
State scope
Scope can range from one component to siblings, a feature subtree, distant branches, multiple React roots, or React + non-React consumers.
Scope often tells you whether lifting state, Context, or an external store is appropriate.
Update frequency and subscription granularity
A useful performance model is:
Higher values make ownership and subscription granularity more important.
Context may be perfect for a theme that changes rarely and a poor fit for high-frequency signals consumed by many expensive components.
State transitions vs external synchronization
Do not use reducers to perform synchronization and do not use Effects as a general state-transition engine.
Client draft vs server record
Suppose /api/customer/42 returns a customer record while the user edits a local form draft.
After saving, the server/cache may be updated or refreshed. Do not force these two lifecycles into one state object simply because their fields look similar.
Avoid “global store by default”
Context is distribution, not ownership
A provider can use both, but they remain different responsibilities.
Ecosystem tools own different categories
Redux Toolkit, Zustand, Jotai, MobX, XState, TanStack Query, SWR, router state, and framework caches are not interchangeable merely because they all involve “state.”
That is healthy when each value has one authoritative owner.
Persistence does not define ownership
Saving data to localStorage does not automatically make storage the live source of truth.
You might initialize React state from storage, let React own the active session state, then synchronize durable changes back. Or you might deliberately wrap storage as an external store with subscription semantics.
Be explicit about which model you are using.
Architecture example
This is usually more maintainable than one universal store containing every category.
Questions before introducing shared/global state
Ask who writes it, who reads it, the authoritative source, required lifetime, whether browser navigation semantics matter, whether it comes from a server, update frequency, subscription granularity, non-React consumers, and what concrete failure mode a new tool solves.
Exercise
Classify search query, modal visibility, API profile, unsaved editor text, theme, browser online status, page number, cart total, and shared external notifications. For each identify source of truth, lifetime, scope, and likely React/ecosystem tool.
Interview questions
Mid-level: What is the difference between client state and server state?
Senior: Why might URL state be preferable to Context for filters?
Staff: How do lifetime, source of truth, update frequency, and subscription granularity influence state architecture?
Summary
References
- https://react.dev/learn/managing-state
- https://react.dev/learn/sharing-state-between-components
- https://react.dev/learn/passing-data-deeply-with-context
- https://react.dev/reference/react/useSyncExternalStore
Next
Continue with useSyncExternalStore and External Subscriptions.