React.StrictMode is a development-only helper that highlights potential problems in React applications. It performs additional checks, warnings, and validations without affecting production builds.
React.StrictMode is a tool that helps developers identify potential problems in their React applications. It runs only in development mode and does not affect production builds.
Think of it as React’s “lint mode” — it performs additional checks and warnings to help write cleaner, future-proof code.
// index.js - enabling StrictMode at root level
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
You can also wrap specific components to isolate checks in smaller parts of the component tree.
// Component demonstrating double execution in StrictMode
import React, { useEffect } from "react";
function Example() {
useEffect(() => {
console.log("Effect executed");
}, []);
console.log("Component rendered");
return <p>Check your console!</p>;
}
export default Example;
When wrapped in StrictMode, the console will log:
// StrictMode intentional double invocation
Component rendered
Effect executed
Component rendered
Effect executed
This helps detect unwanted side effects such as API calls during rendering.
Use this simulator to visualize how StrictMode forces your effects to run twice (mount -> unmount -> mount) to catch cleanup bugs.
useEffectGoal: Understand how React.StrictMode improves code safety and future compatibility.