Strict Mode Effects
In one line
Strict Mode double-invokes effects (mount, cleanup, remount) to catch missing cleanup logic.
In simple words
In React 18 Strict Mode, useEffect runs mount→cleanup→mount on initial render. This simulates mounting, unmounting, and remounting a component — catching bugs where:
- Cleanup is missing — subscriptions, event listeners, timers leak
- Effect runs twice — double-fetching, double-subscribing
- Setup assumes single mount — breaks on fast page transitions
This is development-only — production runs effects once. The goal: if your effect works correctly with mount→cleanup→mount, it'll work correctly in production with just mount.
Fix: ensure every effect has proper cleanup. If you subscribe in setup, unsubscribe in cleanup. If you start a timer, clear it in cleanup.
Example
import { useEffect } from "react";
// BAD — no cleanup, will cause issues in Strict Mode
function BadTimer() {
useEffect(() => {
setInterval(() => console.log("tick"), 1000);
}, []); // Leaks interval!
return <div>Timer</div>;
}
// GOOD — proper cleanup
function GoodTimer() {
useEffect(() => {
const id = setInterval(() => console.log("tick"), 1000);
return () => clearInterval(id); // Cleanup!
}, []);
return <div>Timer</div>;
}Strict Mode runs mount→cleanup→mount to catch missing cleanup. The GoodTimer clears its interval, so remounting works correctly.
Common confusions
Confused with: double rendering
The difference: Strict Mode double-invokes render functions AND runs effects mount→cleanup→mount. Double-rendering catches impure renders. The effect remount catches missing cleanup. Both are development-only and don't affect production.
Related terms
Related Resources
Related Lessons
- React Best Practices
Strict Mode effects.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.