If a prop is only used in the context of nextProps, the lint rule mistakenly thinks that the prop is never used.
Here's a repro case:
import React, {PropTypes} from "react";
export default React.createClass({
propTypes: {
foo: PropTypes.bool, // this line gets flagged when it shouldn't
bar: PropTypes.func,
},
componentWillReceiveProps (nextProps) {
if (nextProps.foo) {
return;
}
},
render () {
this.props.bar;
return <div />;
}
});
What's the use case for a prop that's not used in the render path?
It might not be idiomatic React, but in this case, we're waiting on a prop
to turn true and when it does, we trigger a route change. You could
imagine a signup form component waiting for nextProps.signupCompleted to
be true, and then redirecting to the homepage.
On Wed, Aug 31, 2016 at 10:07 PM Jordan Harband [email protected]
wrote:
What's the use case for a prop that's not used in the render path?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/yannickcr/eslint-plugin-react/issues/801#issuecomment-243977273,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABXjcQczEGkM2OE-QOXKuMMCFpjTElA9ks5qll2fgaJpZM4JyNKK
.
This will be fixed by https://github.com/yannickcr/eslint-plugin-react/pull/792
Great! Thanks @EvNaverniouk
Hi, I still get this same error. 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.
still getting this error too.
This should be fixed. @wx2228. what version of eslint-plugin-react do you use? If using the latest, could you provide sample code of what is failing? Then I can look into it. Thanks!
@jseminck thanks for the prompt reply. I am using 6.10.3. I will upgrade it
it also wont check nextProps if componentWillReceiveProps is declared as an arrow function.
@andfelzapata would you file that as a separate issue?
Most helpful comment
Hi, I still get this same error. When we use a prop only with
nextPropsto set the state in thecomponentWillRecieveProps(nextProps)method and not elsewhere we getreact/no-used-prop-typeserror for the prop in the propTypes block.