When a property is used in getDerivedStateFromProps but not defined in defaultProps this doesn't give me a warning or error.
In the below case baz gives me a react/prop-types error, I expect this same error from bar.
class TestClass extends React.PureComponent {
static getDerivedStateFromProps(props) {
const { foo, bar } = props;
return {
foobar: foo(bar),
};
}
render() {
const { baz } = this.props;
const { foobar } = this.state;
return <div>{foobar}</div>;
}
}
TestClass.defaultProps = {
foo: PropTypes.func.isRequired,
};
What React version is specified in your eslint config's "settings"? If it's not 16.3+, then the plugin won't know it's a lifecycle method.
It's set to 16.4, so that should not be the issue. It does complain about non "UNSAFE_" legacy lifecycle methods.
Perhaps that example is meant to say not defaultProps but propTypes?
Most helpful comment
It's set to 16.4, so that should not be the issue. It does complain about non "UNSAFE_" legacy lifecycle methods.