-
-
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
no-unused-prop-types - cannot detect usage within componentWillReceiveProps #884
Comments
Can you provide the exact code in question? |
Below is a simplified example. We have a custom higher-order component that handles form submission, validation, etc. and it injects a import React, { Component, PropTypes } from 'react';
export default class UserForm extends Component {
static propTypes = {
firstName: PropTypes.string,
lastName: PropTypes.string,
onSubmit: PropTypes.func,
hasSubmitted: PropTypes.bool,
}
static defaultProps = {
hasSubmitted: false,
}
state = {
isEditable: false,
};
componentWillReceiveProps(nextProps) {
if (nextProps.hasSubmitted) {
this.setState({ isEditable: false });
}
}
handleEdit = () => {
this.setState({ isEditable: true });
}
render() {
return (
<form onSubmit={this.props.onSubmit}>
<label htmlFor="firstName">First Name</label>
<input type="text" id="firstName" name="firstName" value={this.props.firstName} disabled={!this.state.isEditable} />
<label htmlFor="lastName">Last Name</label>
<input type="text" id="lastName" name="lastName" value={this.props.lastName} disabled={!this.state.isEditable} />
{this.state.isEditable ? (
<div>
<button>Cancel</button>
<button type="submit">Update</button>
</div>
) : (
<div>
<button onTouchTap={this.handleEdit}>Edit</button>
</div>
)}
</form>
);
}
} |
I'm unable to reproduce the issue using the code your provided. The rule currently supports prop checking for Can you confirm you're running the latest version of |
Here is repository that replicates the issue using the latest If you run |
I think I have encountered this same bug. I noticed that the bug only appears if I access the prop with a dot ( I'm going to see if I can make a PR fixing this! |
It looks like you have to destructure the props from |
This is fixed. Thanks :) |
That's not up to me :-) thanks for all your triage help! |
@marcgrr , Thanks.. It worked for me as well. |
I have a component where I'm only referencing a prop within
componentWillReceiveProps(nextProps)
andreact/no-unused-prop-types
is not picking it up.It's probably a bad practice that I need to revisit on my end, but wondering if you guys think it's something the rule should handle.
The text was updated successfully, but these errors were encountered: