-
-
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-props unable to handle inline functions #1309
Comments
It's difficult to catch every case. In the meantime, I'd suggest always destructuring all props and state and context at the top of your functions, which has the side benefit of bypassing this problem. |
Hmm alright I will see if that helps. Thanks for the reply. |
@Robinfr It looks like your case works with master as well as with v7.1.0. Which version are you using? |
I'm using 7.1.0.. so this is a bit curious 😕 EDIT: You are correct however, with this test case I don't get errors. I will check what's different in the real case then... |
Updated example: import React from 'react';
const Thing = (props) => (
<div>
<div>
{(() => {
if (props.enabled && props.testString) {
return (
<span>Enabled!</span>
);
}
return (
<span>Disabled..</span>
);
})()}
</div>
</div>
);
Thing.propTypes = {
enabled: React.PropTypes.bool,
testString: React.PropTypes.string
};
Thing.defaultProps = {
enabled: false
};
export default Thing; In this case, you have two props, 'enabled' PropType is defined but prop is never used react/no-unused-prop-types |
@Robinfr, thanks for the updated example. It did uncover a bug in the rule. I created a PR to fix it. Stay tuned for the next release! |
When you do the following, no-unused-props is triggered even though the props are used:
The text was updated successfully, but these errors were encountered: