Skip to main content

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​

Classify state before choosing a tool
Local UI state
One component / nearby subtree owns interaction state.
Shared client state
React-owned state coordinated across multiple consumers.
Server state
Remote authoritative data with fetch/cache lifecycle.
URL state
Navigable, shareable state owned by browser/router semantics.
External store state
Underlying mutable source lives outside React state.
Derived state
Calculated from existing sources rather than owned independently.

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.

Why state locality is valuable
Clear owner
You know who writes the value.
Small update scope
Unrelated parts of the app do not depend on it.
Low coupling
Feature deletion/refactoring stays easier.

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.

How should shared client state scale?
A common parent can own it clearlyLift state and pass props
A feature subtree needs broad accessConsider Context / reducer + Context
Lifetime/subscription requirements exceed the React treeConsider 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.

Server state has a remote-data lifecycle
Fetch
loading · request deduplication · pagination
Cache
lifetime · staleness · background refresh
Change
mutations · optimistic updates · invalidation · retries

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.

When the URL should own the value
Refresh
The same view should reappear after reload.
Share
Copying the URL should reproduce the view.
History
Back/forward navigation should represent state transitions.

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.

External does not mean global
External
The storage/subscription source lives outside React.
Global
A separate question about scope and number of consumers.

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.

Derived value vs duplicated state
Derive
tasks → calculate completed count during render
Duplicate
tasks + completed state must now be manually synchronized

Classifying one screen​

An ecommerce page can contain several state categories at once.

One screen, different owners
Product data
server state
Route product ID
URL state
Quantity input
local UI state
Cart draft
shared client state
Cart total
derived state
Online status
external browser subscription

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.

Examples of source of truth
Input draft
React component / feature owner
Order status
server
Search query
URL/router
Online status
browser platform
Cart total
derived from cart items

Many state bugs are really multiple competing sources of truth.

State lifetime​

State lifetime should match ownership
1component lifetime
2route lifetime
3feature-provider lifetime
4application lifetime
5browser/session lifetime
6server/cache 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:

Shared-state pressure
update frequency × subscriber count × render cost

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​

Reducers and Effects solve different problems
State transition
current cart + action → next cart · reducer territory
External synchronization
current roomId → connect external chat system · Effect territory

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.

Remote record and local draft have different lifecycles
Server state
authoritative persisted customer record
Local draft
unsaved editing state that may intentionally differ

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”​

Two components need this value—what now?
State can stay with one nearby ownerKeep it local / lift to common parent
A coherent subtree needs broad accessContext or reducer + Context may fit
Independent lifetime, non-React access, or fine-grained subscriptions are requiredEvaluate an external store
The authoritative source is server or URLKeep that source of truth instead of creating generic global client state

Context is distribution, not ownership​

Do not confuse the transport with the owner
useState / useReducer
Own React state.
Context
Distributes access through a subtree.

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.”

A mature app can use multiple tools without duplicating ownership
Server cache
TanStack Query / framework data layer
Feature client state
Context / reducer / store
Local UI
useState
Navigable filters
URL/router

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​

State architecture by ownership category
URL/router
projectId · filters · page
Server cache
projects · users · activity
Feature providers
editor reducer · checkout workflow
Local component state
menus · drafts · focused row
External store
cross-root / non-React subscription data

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​

State architecture sequence
1classify the value
2identify source of truth
3choose scope + lifetime
4consider frequency + subscribers
5choose smallest fitting primitive/tool
6avoid duplicated ownership

References​

Next​

Continue with useSyncExternalStore and External Subscriptions.