Closed
Description
When we use a prop only with nextProps to set the state in the componentWillRecieveProps(nextProps) method and not elsewhere we get react/no-used-prop-types
error for the prop in the propTypes block.
Same as #801
Here is an excerpt of my code:
class MyComponent extends React.Component {
static propTypes = {
isLoading: React.PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
error: React.PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
}
static defaultProps = {
isLoading: true,
error: false,
};
constructor(props) {
super(props);
this.state = {
isLoading: true,
error: false,
};
}
componentWillReceiveProps(props) {
if (props.error) {
this.setState({ ...this.state, error: props.error });
} else {
this.setState({
...this.state,
isLoading: props.isLoading,
error: false,
});
}
}
// the rest of the code
}
Notice I have to use // eslint-disable-line react/no-unused-prop-types
to avoid the warnings