I am trying to reset React state variables (to default values) in a container using setState() method. But getting the following error
Warning: setState(..
componentWillReceiveProps is deprecated now (since June'18)
You should use one of the alternatives presented in the react docs instead.
In your case I guess it could be justified to use the 'not so recommended' alternative 1 version that uses getDerivedStateFromProps, as you are just recomputing the state vars:
getDerivedStateFromProps(props, state) {
if(props.resetMessages) {
const company = Object.assign({}, state.company);
company.id = 0;
company.messages = [];
return {
company: company
}
}