React Patterns That Actually Scale

Compound components, render props vs hooks, custom hook patterns, and state management decisions that age well.

By Rais Helmy, IT consultant in Kuala Lumpur, Malaysia.

React Patterns That Actually Scale.

Compound components, custom hooks, state colocation, and the patterns that make codebases readable six months later.

pattern 1 · compound components

Expectation: best practice

  • Compound components share implicit state via context — consumers compose the UI without prop drilling.
  • Clean public API: <Tabs>, <Tabs.List>, <Tabs.Panel>.
  • Flexible — caller controls layout, library controls behaviour.

Reality: what most teams do

  • God component with 20 boolean props: showHeader, hasFooter, isCollapsible.
  • Render prop chaos — nested callbacks, unreadable JSX trees.
  • "Props explosion" — every variation adds a new prop.

Better approach (code)

// ✦ Compound component — clean API
<Tabs defaultValue="profile">
  <Tabs.List>
    <Tabs.Trigger value="profile">Profile</Tabs.Trigger>
    <Tabs.Trigger value="billing">Billing</Tabs.Trigger>
  </Tabs.List>
  <Tabs.Panel value="profile"><ProfileForm/></Tabs.Panel>
  <Tabs.Panel value="billing"><BillingForm/></Tabs.Panel>
</Tabs>

Common mistake (code)

// ✗ Props explosion
<Tabs
  tabs={[{label:'Profile',content:<ProfileForm/>},
        {label:'Billing',content:<BillingForm/>}]}
  defaultIndex={0}
  showBorder={true}
  alignment="left"
  onChange={(i) => trackTabChange(i)}
  renderHeader={(tab) => <span>{tab.label}</span>}
/> // add one more variant → another prop

pattern 2 · custom hooks vs context

Expectation: best practice

  • Custom hooks for reusable logic — auth, forms, data fetching, local state patterns.
  • Context for cross-tree shared values that change infrequently: theme, user, locale.
  • Zustand / Jotai for frequent client state updates — avoids context-triggered re-renders.

Reality: what most teams do

  • Context for everything, including high-frequency state like cart totals and search queries.
  • Duplicated fetch logic in 30 components instead of a shared useOrders() hook.
  • Redux for a 5-page app — boilerplate heavier than application logic.

Example (code)

// ✦ Custom hook — reusable fetch logic
function useOrders(userId) {
  const [orders, setOrders] = useState([]);
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    fetchOrders(userId).then(data => {
      setOrders(data); setLoading(false);
    });
  }, [userId]);
  return { orders, loading };
}

// ✦ Use anywhere — no context needed
function OrdersPage({ userId }) {
  const { orders, loading } = useOrders(userId);
  if (loading) return <Spinner/>;
  return <OrderList orders={orders}/>;
}

State belongs as low in the tree as possible.

Lifting state all the way to the root causes global re-renders for local concerns. A modal's open/close state should live in the component that triggers it — not in AppContext.

Lift state when

Two sibling components both need the value · A parent needs to respond to child changes · The value is truly global (user session, theme)

Keep it local when

Only one component needs it · It's transient UI state (hover, focus, open/close) · It resets when the component unmounts

→ Rule: colocate first. Lift only when you have a concrete reason — not "just in case".

state management decision framework

  • Server state: React Query / SWR - Fetch, cache, synchronise — purpose-built
  • Global UI state: Zustand / Jotai - Fast, no boilerplate, no context re-renders
  • Form state: React Hook Form - Uncontrolled forms, minimal re-renders
  • URL state: useSearchParams - Shareable, bookmarkable filter state
  • Local UI state: useState / useReducer - Default choice for component-local state
  • Context: Theme / Auth only - Infrequently changing, read-heavy values