-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react/no-used-prop-types error thrown when a prop is only used in nextProps #1142
Comments
Please can you fix this - having the same issue :( |
I could try and take a look at this. Not sure how far I will get. I see that the same issue exists with |
Hi, This issue seems fixed in #1106 - E.g. it should work on the 7.0.0 release (which was released after this issue was created.). @joetidee can you please let me know what version you use and what is failing for you? Just to be clear, the example code from the original issue works. See below for a more concise example: The following example passes eslint-plugin-react test cases so it should work class Hello extends Component {
static propTypes = {
foo: PropTypes.string
bar: PropTypes.string
};
componentWillReceiveProps (nextProps) {
if (nextProps.foo) {
return true;
}
}
render() {
return (<div>{this.props.bar}</div>);
}
} The following example does NOT pass eslint-plugin-react test cases so it should NOT work class Hello extends Component {
static propTypes = {
foo: PropTypes.string
bar: PropTypes.string
};
shouldComponentUpdate (nextProps) { // replace componentWIllReceiveProps with shouldComponentUpdate
if (nextProps.foo) {
return true;
}
}
render() {
return (<div>{this.props.bar}</div>);
}
} I identified a few issues:
I'll get one or a few PR-s out for this within the next few days. As I believe we might as well fix all three points but it may be better to handle them one issue at a time. :) |
Excellent - thanks - have upgraded to 7.0.0 and now fixed. |
#1232 hopefully has solved this; we can reopen after the next release if not. |
@mqklin could you file a new issue about that? |
still not working here using |
@pkhodaveissi if you pass a props or state object around, you’ve both defeated all static analysis and also, you’ve given up control of a mutable object that your component depends on, a bad practice. Always extract every prop/state from the objects immediately, and pass those around. |
Thank you for your helpful feedback
…On Sat, May 25, 2019 at 7:34 PM Jordan Harband ***@***.***> wrote:
@pkhodaveissi <https://github.com/pkhodaveissi> if you pass a props or
state object around, you’ve both defeated all static analysis and also,
you’ve given up control of a mutable object that your component depends on,
a bad practice.
Always extract every prop/state from the objects immediately, and pass
those around.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1142>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA72IK2ZU264B35HFZOTWS3PXFIQLANCNFSM4DG3ITZA>
.
|
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:
Notice I have to use
// eslint-disable-line react/no-unused-prop-types
to avoid the warningsThe text was updated successfully, but these errors were encountered: