ReactTraining / react-media

CSS media queries for React
MIT License
2.44k stars 115 forks source link

Switch from componentWillMount to constructor #125

Closed tonyjmnz closed 5 years ago

tonyjmnz commented 5 years ago

Prevents warning on React 16 strict mode

Even though the warning suggests to replace it with componentDidMount, opted to replace it with constructor instead so that it is run before the component mounts, just like componentWillMount


Warning: Unsafe lifecycle methods were found within a strict-mode tree:
    in Provider (at index.js:15)

componentWillMount: Please update the following components to use
componentDidMount instead: Media

Learn more about this warning here:
https://fb.me/react-strict-mode-warnings```
edorivai commented 5 years ago

Hi @tonyjmnz :wave:, thanks for the PR.

This issue has already been addressed and published as a prerelease available at react-media@next. Please try it out and let me know if that version solves the warnings at your end.