ReactEasy
What triggers a re-render?
A component re-renders when its own state changes (useState, useReducer), when its parent re-renders (by default, regardless of whether props changed), when a context it reads changes, or when an external store it subscribes to via useSyncExternalStore changes. Changing a ref or a regular variable never triggers a re-render.
The triggers
- State update with a value different from the current one (by
Object.is). - Parent re-render: all children re-render by default. Props changing is not required; this surprises many people.
memo(or the React Compiler) makes the child skip when props are shallowly equal. - Context change: every component calling
useContext/usefor that context re-renders when the provider's value changes, even if memoized. - External store change: hooks built on
useSyncExternalStore(Redux'suseSelector, Zustand) re-render when the selected value changes. - Hook dependencies inside libraries that set state (data fetching libraries updating on refetch).
- Development only: Strict Mode double-renders; Fast Refresh re-renders on file save.
What does not
- Mutating
ref.current. - Mutating state objects in place (and then not setting new references).
- Changes to module-level variables.
- Calling the setter with the same value (React may render the component once more before bailing out, but children do not re-render).
Debugging
React DevTools Profiler with "Record why each component rendered" lists the cause for each render: hooks changed, props changed, parent rendered, or context changed.
Code example
tsx
1import { createContext, memo, use, useRef, useState } from "react";23const ThemeContext = createContext("light");45const Leaf = memo(function Leaf({ label }: { label: string }) {6 const theme = use(ThemeContext); // re-renders on context change even though memoized7 console.log("Leaf render", label, theme);8 return <span>{label} ({theme})</span>;9});1011export function Triggers() {12 const [count, setCount] = useState(0);13 const [theme, setTheme] = useState("light");14 const clicks = useRef(0);1516 return (17 <ThemeContext value={theme}>18 <button onClick={() => setCount((c) => c + 1)}>State change ({count})</button>19 <button onClick={() => setTheme((t) => (t === "light" ? "dark" : "light"))}>Context change</button>20 <button onClick={() => (clicks.current += 1)}>Ref change (no re-render)</button>21 <Leaf label="memoized" /> {/* skips parent re-renders, not context changes */}22 </ThemeContext>23 );24}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.