`no-unused-prop-types` doesn't check `nextProps` of `componentWillReceiveProps`
See original GitHub issueIf 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 />;
}
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:14
- Comments:10 (3 by maintainers)
Top Results From Across the Web
reactjs - How to check what props changed in ... - Stack Overflow
If you used componentWillReceiveProps to “reset” some state when a prop changes, ... static getDerivedStateFromProps(nextProps, prevState) { if(nextProps.
Read more >React.Component
This page contains a detailed API reference for the React component class definition. It assumes you're familiar with fundamental React concepts, ...
Read more >React17, or how to get rid of “componentWillReceiveProps”?
This method doesn't have access to the component instance. If you'd like, you can reuse some code between getDerivedStateFromProps() and the ...
Read more >React Component lifecycle methods, part II | by Yassi Mortensen
within componentWillReceiveProps , check which props will change. If the props changed, act on it. shouldComponentUpdate(nextProps, nextState).
Read more >componentWillReceiveProps vs getDerivedStateFromProps ...
I use react-navigation to navigate to a screen in response to the notification handler. Its a DrawerNavigator so doesn't take props. However ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, I still get this same error. When we use a prop only with
nextProps
to set the state in thecomponentWillRecieveProps(nextProps)
method and not elsewhere we getreact/no-used-prop-types
error for the prop in the propTypes block.@jseminck thanks for the prompt reply. I am using 6.10.3. I will upgrade it