Strict Mode is a development tool that helps find potential problems in components.
Simple analogy: Imagine you are taking an exam. A strict teacher (Strict Mode) asks tricky questions and checks every detail. This helps find errors BEFORE you get to work (production). In real life (production) the teacher is kind and does not nitpick.
What Strict Mode does:
How to use:
1import { StrictMode } from "react";23function App() {4 return (5 <StrictMode>6 <MyApp /> {/* Everything inside is checked */}7 </StrictMode>8 );9}
What happens with double invocation:
1function App() {2 console.log("App rendered"); // This will log TWICE in dev mode34 useEffect(() => {5 console.log("Effect ran"); // This will also run TWICE in dev mode6 return () => console.log("Cleanup");7 }, []);89 return <h1>Hello</h1>;10}11// Output in dev:12// "App rendered"13// "App rendered"14// "Effect ran"15// "Cleanup"16// "Effect ran"
Why double invocation exists: React wants to ensure your components are resilient to being mounted and unmounted. If your effect doesn't properly clean up, the double invocation in dev will expose the bug.
Important: