Warning `Unsafe legacy lifecycles will not be called for components ...` keeps appearing
See original GitHub issueDo you want to request a feature or report a bug? Might be a bug?
What is the current behavior? Replaced componentWillReceiveProps() with a newly added getDerivedStateFromProps() but the warning keeps appearing in the console.
I doubted the higher order component at first sight, so removed all the coupling with this component’s higher order wrapper. I also removed children
in render() in an effort to remove all the side effects.
Apparently there’s no componentWillReceiveProps() in this component but I cannot get rid of this warning. The only thing I could do was to explicitly assign null to this.componentWillReceiveProps
, then the warning was gone.
Am I missing something or is it a bug? I also wish this warning could be optionally turned off in development environment. (Considering the legacy React libraries still use them and can be injected by e.g. HOC)
class RootContainer extends React.Component {
constructor() {
super();
this.state = {
};
this.componentWillReceiveProps = null; // Only way I can turn that warning off
}
static getDerivedStateFromProps(nextProps, prevState) {
// ...
return prevState;
}
render() {
return (
<div>1</div>
// <Root>
// {this.props.history
// ? this.props.children
// : null}
// </Root>
);
}
}
// ...
export default RootContainer;
// export default withRouter(connect(makeMapStateToProps)(RootContainer));
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
What is the expected behavior?
No warning (or at least to turn that off by option even in development
environment)
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
- React 16.3.0
- React-DOM 16.3.0
- React-Redux 5.0.7
- React-Router-DOM 4.2.2
UPDATE Apr 4
- React-hot-loader 4.0.0 (CAUSE OF WARNING)
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
@OleksandrBudik Make sure you use the latest
react-redux
(there are updates available both for 4.x and 5.c branches). Most likely you’re using an older version that copies all static methods (including the new lifecycle) to the wrapping component, causing this warning. The newer version skips this lifecycle.I have the same issue. It also causes serious bug alongside with warning. It fires getDerivedState… every time component updates.
It seems to be a
react-redux
issue. I’ve updated to the5.1.0
Didn’t help.