Lesson 4 of 9 · 25m
Rendering Is a Data-Flow Problem
Understand React render as a consequence of state and identity changes, then design component trees so updates stay close to the state that caused them.
Most React performance advice starts too low. It jumps to memoization before asking why half the application re-rendered when a checkbox changed. Rendering is a data-flow problem first. State changed; React rendered the owner; children rendered unless something proved they did not need to. If the owner is too high in the tree, the blast radius is architectural.
Render is the default, not the enemy
React rendering is usually cheap compared with DOM mutations, layout, network waterfalls, and JavaScript parsing. Do not fear render itself. Fear uncontrolled render scope and expensive work repeated inside render.
function App() {
const [sidebarOpen, setSidebarOpen] = useState(false)
return <><Sidebar open={sidebarOpen} /><Dashboard /></>
}When sidebarOpen changes, App renders and Dashboard may render with it. Sometimes that is fine. On a heavy dashboard, it is a design problem.
Move state closer to the interaction
The cheapest update is the one that does not cross a huge component boundary:
function SidebarShell() {
const [open, setOpen] = useState(false)
return <Sidebar open={open} onToggle={() => setOpen(v => !v)} />
}
function App() {
return <><SidebarShell /><Dashboard /></>
}This is ownership design, not micro-optimization. Hoist state because multiple consumers need it, not because useState felt safer at the top.
Split state by change frequency
A single object can couple unrelated update rhythms:
const [ui, setUi] = useState({
query: '', selectedTicketId: null, sidebarOpen: false, theme: 'dark',
})Typing in the query field now conceptually changes the same object as theme selection. Separate fast-changing state from slow-changing state, and pass narrow values to children.
Context broadcasts by value identity
Context is dependency injection, not a performance boundary. Every consumer re-renders when the value identity changes:
const value = useMemo(() => ({user, permissions}), [user, permissions])
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>That memoization is honest only if user and permissions are stable upstream. If a provider value contains volatile UI state, every consumer pays. Split identity context from volatile UI context, or keep volatile state out of global context.
Server state is not component state
Server data has cache lifetime, invalidation, and concurrency semantics. Query caches and router loaders can keep it out of local component state, so components subscribe to what they use instead of receiving broad server objects through props.
Field notes
- Rendering too much is usually a state placement problem, not a missing useMemo problem.
- Context does not optimize updates; it broadcasts them.
- Fast-changing input state should live near the input unless other components truly need it.
- If removing a broad provider breaks twenty unrelated components, the data flow was already too implicit.
Was this lesson helpful?