question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-unused-prop-types` doesn't check `nextProps` of `componentWillReceiveProps`

See original GitHub issue

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 />;
  }
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
mjilugucommented, Apr 7, 2017

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.

1reaction
wx2228commented, Jul 16, 2017

@jseminck thanks for the prompt reply. I am using 6.10.3. I will upgrade it

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found