I am upgrading my project to react 16.3.1 but in components with HOC generated with react-apollo I am getting this errors and my app crashed.
"Apollo(SubmittedFormsList): Did not properly initialize state during construction. Expected state to be an object, but it was undefined."
this is the code I am expecting to work (Recommended By React):
Error: "TypeError: prevState is null"
static getDerivedStateFromProps(nextProps, prevState) {
if(nextProps.showModal !== prevState.showModal) {
console.log('recived new prop');
return { showModal: true };
} else {
return null
}
};
and this is the code actually works for me (NOT Recommended By React):
componentWillReceiveProps(nextProps) {
if(nextProps.showModal !== this.state.showModal) {
console.log('recived new prop');
this.setState({ showModal: true }) ;
};
};
We are having the exact same issue, and I think it is due to the fact that react apollo is using an outdated hoist-non-react-statics that doesn't support React 16.3, but I'm not 100% sure on that... In our case the app doesn't crash, but just throws that warning in the console. Im going to debug it a bit more and if I find the cause, I'll report back!
same issue here
This should normally be fixed. Be sure you have te latest version of react-apollo by running yarn upgrade react-apollo.
Seeing same warning here.
This issue should be closed now.
Closing - housekeeping
Most helpful comment
We are having the exact same issue, and I think it is due to the fact that react apollo is using an outdated hoist-non-react-statics that doesn't support React 16.3, but I'm not 100% sure on that... In our case the app doesn't crash, but just throws that warning in the console. Im going to debug it a bit more and if I find the cause, I'll report back!