What Actually Runs When a React Component Re-renders
Misreading console logs as evidence of wasteful DOM updates leads developers to prematurely add memoization or restructure state, making code harder to maintain without fixing a real bottleneck. Understanding the render-versus-commit split and Effect dependency rules prevents the most common React performance dead ends.
When a React component re-renders, the entire function body executes again: local variables, derived calculations like total price, event handlers, and the returned JSX all get new values based on the latest props and state. State itself, however, is preserved by React across renders—the initial value passed to useState is ignored after the first mount.
React then diffs the new JSX against the previous output and commits only the necessary DOM changes. A component function logging twice does not mean the DOM was rebuilt twice. Effects follow their own dependency rules; a component re-executing does not force every Effect to re-synchronize.
Side effects like network requests or DOM mutations belong in event handlers or Effects, not directly in the render body. Before reaching for useMemo or useCallback, developers should first confirm that a re-render is actually causing a measurable performance problem, not just extra log lines.
Many React developers conflate "the component function ran" with "the DOM updated," which leads to unnecessary optimization work. The render phase is pure computation; only the commit phase touches the DOM.
The article's distinction between state, local variables, and derived data is a mental model that, once internalized, eliminates an entire category of useEffect overuse and stale-closure bugs.
Strict Mode's double-invocation is still widely misunderstood as a bug rather than a development-only purity check, causing developers to mistrust their own logging.
The advice to defer useMemo and useCallback until a profiler shows a problem runs counter to much online React content that treats them as default safeguards, but it aligns with the React team's own recommendations.