Skip to main content

Rules of React visual mental model

The Rules of React protect the assumptions React uses to render, re-render, interrupt, retry, and optimize your components safely.

The four core contracts
PurityRender is a calculation

Components and Hooks should be idempotent for the same relevant inputs and should not perform external side effects during render.

ImmutabilityProps and state are snapshots

Treat values as read-only for the current render and create next values instead of mutating previous snapshots.

OwnershipReact calls Components and Hooks

Use components through JSX and Hooks through React component/custom-Hook execution, rather than invoking them as arbitrary functions.

Hook orderHooks stay at the top level

Stable call order lets React associate each Hook call with the correct state and lifecycle slot across renders.

Purity makes rendering restartable​

Why pure rendering matters
React starts rendering a component
Pure calculations are safe to run again

Repeating render does not duplicate purchases, subscriptions, analytics writes, or external mutations.

React can optimize and schedule safely

Side effects belong at explicit boundaries​

Where should side effects happen?
Render

Calculate UI only.

Event handler

Perform work caused by a specific user interaction.

Effect

Synchronize the rendered component with an external system.

Hook order is positional identity​

Hook call order across renders
Render AStable order

useState → useContext → useEffect

Render BSame order

useState → useContext → useEffect

Conditional Hook call breaks the mapping
Render ACondition true

useState → useEffect → useRef

Render BCondition false

useState → useRef

React owns component invocation​

Component function vs component element
Profile(props)

Direct function calls bypass React's component execution model and can break Hook and identity assumptions.

<Profile {...props} />

JSX lets React control when the component executes and how its identity participates in the tree.

Debug rule violations by category​

What kind of React rule might be broken?
External work happens while renderingMove it to an event handler or synchronization Effect.
Props/state objects are changed in placeCreate a new next value and preserve previous snapshots.
Hooks appear inside conditions, loops, callbacks, or after early returnsMove Hook calls to stable top-level positions.
A component function is invoked directlyRender it through JSX so React owns execution and identity.
A Hook argument or returned value is mutated unexpectedlyTreat values passed across Hook/JSX boundaries as immutable contracts.

Keep this mental model​

Rules of React in one picture
Pure render + immutable snapshots
Stable component and Hook execution model
React can retry, schedule, lint, and optimize safely

Continue with Purity, Immutability and Render Safety for the detailed rules, examples, and debugging guidance.