• React
  • State Management
  • Design Patterns
  • Technical Debt
  • Scalability

React Design Patterns That Actually Scale

Implement React state management best practices to reduce bugs and technical debt.

React Design Patterns That Actually Scale

React state management creates technical debt through synchronization failures, not architecture complexity. A duplicated state variable introduces two representations of the same fact. Every update path must keep them aligned. A missed synchronization produces stale UI, incorrect totals, or broken validation. The React Compiler v1.0, released October 7, 2025, automates memoization but does not fix synchronization bugs caused by duplicated state, unclear ownership, or incorrect Effects.

React's current documentation identifies five core state-structure rules: group related state, avoid contradictory state, avoid redundant state, avoid duplicated state, and avoid deeply nested state. Data calculable from existing props or state should remain derived during render rather than being stored separately. An Effect is unnecessary when it only transforms or synchronizes React state with other React state; such logic should generally run during rendering or inside the event handler that caused the change.

The single source of truth principle states that each unique piece of state should have one owning component, with shared state moved to the closest common parent. React 19.3 is the current reference version as of December 1, 2026. This guide shows how to structure React apps to reduce bugs and technical debt by keeping state minimal, deriving values during render, using Effects only for external synchronization, localizing state to prevent prop drilling, and organizing features for cohesion and scalability.

Keep State Minimal and Local

Store a value in state only if it must persist across renders and cannot be derived. Redundant state creates synchronization defects. Storing both items and filteredItems, or both firstName, lastName, and fullName, creates multiple representations of the same fact. Every update path must keep them synchronized; a missed path produces stale UI.

JavaScript
// Before: duplicated and synchronized state
const [items, setItems] = useState([]);
const [filteredItems, setFilteredItems] = useState([]);

useEffect(() => {
  setFilteredItems(items.filter(item => item.active));
}, [items]);

// After: one source of truth
const [items, setItems] = useState([]);
const filteredItems = items.filter(item => item.active);

Keep transient UI state—input text, open menus, hover state, wizard step—at the smallest component boundary that needs it. Keep server or remote data in the data-fetching or cache layer rather than duplicating it across unrelated component states. Keep URL state in the URL when deep links, browser navigation, or shareability are requirements.

Classify every value before adding state. If it can be derived from props or existing state during render, derive it. If it must persist across renders and cannot be calculated, store it. This classification prevents the synchronization paths that create bugs.

Derive State During Render, Don't Duplicate

React recommends calculating derived values during render instead of storing them separately. A state update inside an Effect occurs after the initial render, schedules another render, and introduces dependency-array behavior, stale-closure risk, and possible update loops.

JavaScript
// Before
const [fullName, setFullName] = useState('');

useEffect(() => {
  setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);

// After
const fullName = `${firstName} ${lastName}`;

Unnecessary Effects add an extra render path. The mechanism is: render from current inputs, run the Effect after commit, call a setter, then render again. This increases interaction latency and rendering work. Move the calculation into the render path and eliminate the intermediate state variable.

Replace derived-state Effects with pure calculations:

JavaScript
// Before
const [visibleProducts, setVisibleProducts] = useState([]);

useEffect(() => {
  setVisibleProducts(
    products.filter(product =>
      product.name.includes(query) && product.inStock
    )
  );
}, [products, query]);

// After
const visibleProducts = products.filter(product =>
  product.name.includes(query) && product.inStock
);

If the calculation is genuinely expensive, profile it first. React Compiler can automatically memoize supported calculations; manual memoization should be reserved for measured cases or compiler-incompatible boundaries. The compiler does not remove synchronization bugs caused by duplicated state—it only reduces the need for routine manual use of useMemo, useCallback, and React.memo.

Use Effects Only for External Synchronization

Effects are intended for external synchronization. Valid use cases include connecting to a non-React system, subscribing to an external data source, controlling a browser API, or responding to lifecycle-driven side effects. They are not a general-purpose replacement for event handlers or derived expressions.

Move event-specific logic into event handlers:

JavaScript
// Before: Effect reacts to a flag created only to trigger an action
const [submitted, setSubmitted] = useState(false);

useEffect(() => {
  if (submitted) {
    analytics.track('order_submitted');
  }
}, [submitted]);

// After: the event is the source of truth
function handleSubmit(order) {
  saveOrder(order);
  analytics.track('order_submitted');
}

This removes an intermediate state variable and makes the causal sequence explicit. The Effect was unnecessary because no external system required synchronization—the action belonged in the event handler that caused it.

Separate server data, client state, and derived view state. Server data includes fetched records, loading state, errors, and cache invalidation. Client state includes drafts, selections, open panels, and optimistic interaction state. Derived view state includes filtered collections, totals, labels, and validation summaries. Do not copy server records into local state unless creating an intentional editable draft or snapshot.

Localize State to Prevent Prop Drilling

State ownership controls synchronization. If two components must change together, keeping separate local copies creates drift. React's recommended mechanism is to remove both local copies, lift the state to their closest common parent, and pass the value and event handlers down.

JavaScript
// Before: two independent owners
function Accordion() {
  return (
    <>
      <Panel />
      <Panel />
    </>
  );
}

function Panel() {
  const [open, setOpen] = useState(false);
  // Panels cannot reliably coordinate
}

// After: one owner
function Accordion() {
  const [openIndex, setOpenIndex] = useState(null);

  return panels.map((panel, index) => (
    <Panel
      key={panel.id}
      isOpen={openIndex === index}
      onOpen={() => setOpenIndex(index)}
    />
  ));
}

Prop drilling is an ownership and boundary problem, not automatically a reason to add global state. First identify whether the value is truly shared, whether an intermediate component can be removed, and whether a context boundary is appropriate. Context can reduce repetitive plumbing, but broad context values may cause many consumers to re-render when the provider value changes.

Split context by change frequency and responsibility. Put stable configuration, authenticated-user identity, or service references in separate contexts from rapidly changing input state. Keep providers close to the consuming feature. Memoize provider values only when profiling or identity stability justifies it; React Compiler may reduce the need for manual memoization but does not change provider notification semantics.

Custom Hooks share logic, not state. Each invocation of a custom Hook owns an independent state instance:

JavaScript
// Independent state: two separate instances
function SearchBox() {
  const search = useSearch();
  // ...
}

function SearchSummary() {
  const search = useSearch();
  // Not the same state as SearchBox
}

A custom Hook should encapsulate reusable behavior; it should not be expected to synchronize state across components. Shared state must be lifted, provided through context, or managed by an external store.

Organize Features for Cohesion and Scalability

Feature-based organization aligns code with state ownership. A practical structure groups UI, state logic, data access, tests, and types by business capability rather than placing all components, Hooks, and reducers in global technical folders:

Text
src/
  features/
    checkout/
      components/
      hooks/
      checkoutReducer.ts
      checkoutApi.ts
      checkout.types.ts
      checkout.test.ts
    search/
      components/
      hooks/
      searchApi.ts
      search.test.ts
  shared/
    ui/
    lib/

This structure makes ownership and dependency direction easier to review. Feature boundaries reduce blast radius. Feature components may use feature Hooks, reducers, API adapters, and shared UI. Shared UI should not import feature-specific state. API modules should expose domain operations rather than leaking transport details into presentation components. Tests should sit beside the feature logic they verify.

Use a reducer for a cohesive state machine:

JavaScript
function checkoutReducer(state, action) {
  switch (action.type) {
    case 'shipping/updated':
      return { ...state, shipping: action.value };
    case 'payment/validated':
      return { ...state, paymentValid: action.value };
    case 'submitted':
      return { ...state, status: 'submitting' };
    case 'submit/succeeded':
      return { ...state, status: 'complete' };
    case 'submit/failed':
      return { ...state, status: 'error', error: action.error };
    default:
      return state;
  }
}

Keep actions domain-oriented, validate transitions in one place, and avoid dispatching actions that merely mirror another state variable. A reducer is appropriate when transitions are numerous or interdependent. Use it when multiple handlers update the same related state, when transitions need consistent validation, or when state logic is difficult to test locally. For simple independent values, useState is usually clearer.

Flat state is easier to update than deeply nested state. Deep object graphs increase immutable-update complexity and make ownership less clear:

JavaScript
// Before
const [plan, setPlan] = useState({
  sections: [{ id: 'a', tasks: [{ id: 't1', done: false }] }]
});

// After
const [tasksById, setTasksById] = useState({
  t1: { id: 't1', sectionId: 'a', done: false }
});
const [sectionTaskIds, setSectionTaskIds] = useState({
  a: ['t1']
});

Keys define state identity. React preserves component state while a component remains in the same position in the tree. Supplying a different key tells React that it is a different component, causing its state and descendants' state to reset. This is useful for resetting forms when switching records, but unstable or index-based keys can associate state with the wrong item after insertion, deletion, or reordering. Use stable domain IDs for list keys. Never use array indexes as keys for reorderable or mutable lists unless item identity is guaranteed to match position.

Use a review checklist before merging state changes. Can any new state variable be calculated from existing inputs? Is the state duplicated in another component, cache, URL, or provider? Which component is the single owner? Is the update caused by a user event, a render calculation, or an external-system synchronization? Does the component need a reducer, or would simple state be clearer? Could a narrower feature boundary remove prop drilling? Are keys stable and semantically tied to item identity? Has a performance claim been verified with profiling rather than inferred from memoization? Is React Compiler enabled and compatible with the code path, or is manual optimization actually necessary?

React Compiler changes the optimization baseline, not the state-design rules. The compiler can automate memoization, but it does not remove synchronization bugs caused by duplicated state, unclear ownership, incorrect Effects, unstable keys, or overly broad providers. State mistakes extend delivery timelines through debugging stale derived values, repairing Effect dependency behavior, coordinating duplicated caches, and untangling global providers.

If your React codebase has accumulated state-management technical debt and could use a second set of experienced eyes on the architecture, that's the kind of work Azguards can help with. Let's talk.

Architect Your Solution → Explore our Platforms & Modernization work →