How to Fix React StrictMode Double-Rendering
DodaTech
Updated 2026-06-26
1 min read
The Problem
In this quick-fix, you'll learn how to handle StrictMode intentional double-invocation of effects. This matters because StrictMode double-rendering catches side effects but confuses developers. In real-world applications, this pattern appears in identifying impure render functions and missing cleanup during development.
The Wrong Way
function App() {
const [count] = useState(0);
useEffect(() => {
console.log('Effect ran');
const interval = setInterval(() => console.log('Tick'), 1000);
}, []);
return <div>{count}</div>;
}
Effect ran Effect ran Tick Tick -- interval leak undetected
The Right Way
function App() {
const [count] = useState(0);
useEffect(() => {
console.log('Effect ran');
const interval = setInterval(() => console.log('Tick'), 1000);
return () => { console.log('Cleanup'); clearInterval(interval); };
}, []);
return <div>{count}</div>;
}
Effect ran Cleanup Effect ran Tick Tick -- cleanup verified
Prevention
- Always provide cleanup functions in useEffect
- Dont rely on effects running once in dev
- Make render functions pure
- StrictMode only affects development
FAQ
This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro