The current implementation of getDerivedStateFromProps() polyfill is not fully correct: it doesn't demand null be returned which is required by the official spec.
function componentWillReceiveProps(nextProps) {
// Call this.constructor.gDSFP to support sub-classes.
var state = this.constructor.getDerivedStateFromProps(nextProps, this.state);
if (state !== null && state !== undefined) {
this.setState(state);
}
}
Instead it should be:
...
if (state !== null && state !== undefined) {
this.setState(state);
}
if (state === undefined) {
console.warn('Warning: getDerivedStateFromProps(): A valid state object (or null) must be returned. You have returned undefined.');
}
}
The current implementation of
getDerivedStateFromProps()polyfill is not fully correct: it doesn't demandnullbe returned which is required by the official spec.Instead it should be: