StrictMode renders components twice in development mode(not production) in order to detect any problems with your code and warn you about those problems. This is used to detect accidental side effects in the render phase. If you used create-react-app
development tool then it automatically enables StrictMode by default.
ReactDOM.render(
<React.StrictMode>
{App}
</React.StrictMode>,
document.getElementById('root')
);
If you want to disable this behavior then you can remove strict
mode.
ReactDOM.render(
{App},
document.getElementById('root')
);
To detect side effects the following functions are invoked twice:
- Class component constructor, render, and shouldComponentUpdate methods
- Class component static getDerivedStateFromProps method
- Function component bodies
- State updater functions
- Functions passed to useState, useMemo, or useReducer (any Hook)