I heard that strict mode helps to write React code in best practices way by throwing warnings for life cycle methods removal.
I read about it from https://medium.co
Warning:
StrictMode
will render the components twice only on the development mode not production.
For instance, if you're using getDerivedStateFromProps
method like so
static getDerivedStateFromProps(nextProps, prevState){// it will call twice
if(prevState.name !== nextProps.name){
console.log(`PrevState: ${prevState.name} + nextProps: ${nextProps.name}`)
return { name: nextProps.name }
}
return {}
}
The getDerivedStateFromProps
method will call twice.
Just to let you know this is not a problem, it's just because you're wrapping your main component with
in the index.js
file.
StrictMode
renders components twice in order to detect any problems with your code and warn you about them.