Strict Mode
Why your components and effects run twice in development, and why that is actually a good thing.
What it is
<React.StrictMode> is a tool for highlighting potential problems in an application.
You usually wrap your entire app in it inside index.js or main.jsx.
Strict Mode's additional checks run only in development. Production does not receive those extra checks.
Why does my code run twice?
Strict Mode performs extra development checks for impure rendering and missing Effect or callback-ref cleanup. These checks do not include ordinary event handlers.
With Strict Mode at the root, the initial Effect probe runs setup, cleanup, then setup again. This tests whether cleanup reverses setup; it is not a promise that the entire DOM is destroyed and recreated. Scope matters: a Strict Mode subtree does not necessarily receive the same initial Effect probe.
Why is that a good thing?
It acts as a stress test for your code.
If you wrote a useEffect that adds an event listener but you forgot to return a cleanup function, Strict Mode will cause that event listener to be added twice. You'll notice the bug immediately in development, rather than it slowly leaking memory in production.
It helps you find impure rendering and incomplete cleanup. You still need to correct the code it exposes.
Test an Effect's cleanup
Compare lifecycle paths with real local subscriptions. The labelled model exposes missing cleanup without pretending production runs development-only checks.
// Model of an Effect subscription
useEffect(() => {
const stop = subscribe();
return () => stop();
}, []);
// Selected lifecycle model:
setup -> cleanup -> setupOwned subscriptions: 0
None. Run the model to inspect the lifecycle.
Compare one setup with the extra development cleanup probe. Correct cleanup leaves one active subscription; missing cleanup exposes a duplicate.
Lifecycle model, not a measurement of this website's React checks. Strict Mode adds checks in development; ordinary updates can still rerun Effects in production. Missing-cleanup subscriptions stay inside this disposable lab.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- Strict Mode is a development-only wrapper.
- Its extra rendering and cleanup checks run in development; initial Effect behavior also depends on Strict Mode scope.
- It exists to expose missing cleanup functions and impure renders.
- Use extra development runs to inspect cleanup and stale work rather than assuming Effects always run once.
Done with this concept?
Mark it complete to track your progress. No login needed.