Intermediate React Interview QuestionsIntermediateConcept
React · Question 49
Why can components, Effects, and ref callbacks appear to run twice in React Strict Mode?
Direct answer
Strict Mode performs extra development-only checks, including extra rendering and setup/cleanup cycles, to expose impure rendering and missing cleanup before those bugs reach production.
- Render checks: pure component logic may be invoked an extra time in development.
- Effect checks: React can run an extra setup -> cleanup -> setup cycle to expose missing cleanup.
- Ref callback checks: callback refs can also receive extra setup/cleanup checks.
- Production: these Strict Mode checks do not add the same duplicate behavior to the production build.
The goal is not to make developers add flags such as didRun.current to suppress the second call. The goal is to make rendering pure and synchronization cleanup correct.