Today I tried React’s new
StrictMode component. Added in React 16.3,
StrictMode is, according to the release notes:
[A] tool for highlighting potential problems in an application. Like Fragment, StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants.
Here’s a heavy-handed way to implement it:
// index.js ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode> document.getElementById('root')
In this scenario,
App and all of its children get help with:
- Identifying components with unsafe lifecycles
- Warning about legacy string ref API usage
- Detecting unexpected side effects
At the time of publishing this post, this will likely mean console warnings about the use of soon-to-be-deprecated lifecycle hooks such as
componentWillMount. You’ll get these errors from dependencies, too, which is why we aren’t using
StrictMode until at least all our dependencies have upgraded to the latest syntax.