While measuring render counts in a React application in development, you notice every component's function body runs twice for a single update. Should you treat that as a performance problem?
answer
- development only, never production
- opt-in via a wrapper component
- doubling is deliberate, not a defect
- it is checking purity, not speed
- dev builds inflate timings anyway
basics
~10 sNo. React's StrictMode deliberately calls component functions twice in development to expose impure renders. Production builds render once, so measure a production build before drawing any performance conclusion from the doubling.
solid answer
~50 sThat doubling is intentional and development-only. Inside a `<StrictMode>` subtree, React invokes component function bodies twice — along with other functions that are supposed to be pure, such as the updater functions you pass to a state setter — so that a render which is *not* pure gives itself away: a `console.log` printing twice, an array being mutated twice, a counter drifting. A correct, pure render produces the same elements both times, and React uses the result of one of them. Production builds do not do this. So it is not a signal about your app's speed, and removing `<StrictMode>` to make the numbers look better throws away a real correctness check. If you want numbers you can trust, profile a production build — development builds also carry extra warnings and bookkeeping that inflate timings across the board.
go deeper
Recognise the doubling as StrictMode's development-only behaviour and say plainly that production renders once, rather than reporting it as a bug you found.
Explain the purpose: React expects rendering to be pure, so it runs those functions twice in development to make impure ones fail visibly instead of subtly.
Show measurement discipline — insist on a production build before quoting any render timing or count, and push back on removing StrictMode as a performance fix.
Treat it as a policy question: StrictMode is a cheap standing correctness check, so the team's stance should be that it stays on in development and that performance claims are only accepted from production profiles.
## What you are actually seeing Wrapping your tree in `<StrictMode>` opts that subtree into a set of development-only checks. One of them is double-invoking functions React expects to be pure. The clearest symptom is a component body running twice per render: a `console.log` at the top of the component prints twice, a render counter increments by two, an array you accidentally push into during render gets two entries. This is not a bug, not a concurrency artefact, and not something production does. It is a deliberate amplifier: React runs the function twice so that impurity becomes visible immediately rather than as a mysterious inconsistency later. ## Why React does it React's model requires rendering to be a pure calculation: given the same props, state and context, a component must return the same result and must not observe or change anything outside itself while doing so. React relies on that to skip renders, to restart interrupted renders, and to render the same component more than once before committing. Code that mutates a module-level array during render, or logs, or writes to a ref while rendering, silently violates the contract and breaks in ways that only appear under load or during a concurrent update. By running the body twice in development, React makes the violation loud. If your render is pure, both runs produce identical elements and the doubling is invisible except in the impure things you added (like logs). If it is not pure, the second run differs and you see it during ordinary development instead of in production. The same idea covers more than the component body — updater functions passed to a state setter, for example, are also expected to be pure and get the same treatment. ## Why it is not a performance signal The doubling exists only in development, and only inside a `<StrictMode>` subtree. A production build calls each component once per render. So a doubled render count says nothing about the cost of the shipped application. Two consequences follow for measurement: - **Do not read development render counts as production counts.** They are inflated by construction inside StrictMode. - **Do not read development timings as production timings either.** Development builds carry extra validation, warnings and profiling bookkeeping that make everything slower, quite apart from StrictMode. If you need trustworthy numbers, profile a production build of the app. If you only want to compare two implementations against each other, relative numbers in development can still be informative, but treat absolute figures as meaningless. ## The wrong reaction The reaction that costs a team real money is deleting `<StrictMode>` because "it makes everything render twice". That does not speed up production by one microsecond — production was never doing it — and it removes the check that would have caught an impure render before it shipped. If the doubling is genuinely getting in the way of a specific measurement, take the measurement in a production build rather than removing the check from the codebase. ## What to say in an interview The short version: "That is `<StrictMode>`, it is development-only, it double-invokes functions React expects to be pure so impure renders surface immediately, and production renders once. I would profile a production build before making any performance claim." That answer demonstrates the thing the question is really testing — that you can tell a deliberate development-time behaviour apart from a real defect in your own code.
- What would a component that is not pure actually do differently on the second invocation?Anything that depends on outside state or changes it. A body that pushes into a module-level array leaves two entries instead of one; one that increments an outer counter jumps by two; one that reads a value it mutated earlier in the same render returns something different. A pure body returns identical elements both times.
- You need real render timings for a page. What is your measurement setup?Build and serve the app in production mode and profile that, since development adds warnings and bookkeeping on every render and StrictMode doubles pure-function calls. Use development profiling only for relative comparisons between two implementations of the same screen, never for absolute numbers you report.
saying these in an interview costs you the question
- Thinks React renders every component twice in production
- Calls it a React bug and deletes StrictMode to fix performance
- Reports development build timings as production numbers
- Assumes the doubling means state updates are applied twice
- Cannot say what the double invocation is checking for