Skip to content
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 doesn't check nextProps of componentWillReceiveProps #801

Closed
bywo opened this issue Sep 1, 2016 · 10 comments
Closed

Comments

@bywo
Copy link

bywo commented Sep 1, 2016

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 />;
  }
});
@ljharb
Copy link
Member

ljharb commented Sep 1, 2016

What's the use case for a prop that's not used in the render path?

@bywo
Copy link
Author

bywo commented Sep 1, 2016

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 notifications@github.com
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
#801 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABXjcQczEGkM2OE-QOXKuMMCFpjTElA9ks5qll2fgaJpZM4JyNKK
.

@EvHaus
Copy link
Collaborator

EvHaus commented Sep 2, 2016

This will be fixed by #792

@bywo
Copy link
Author

bywo commented Sep 2, 2016

Great! Thanks @EvNaverniouk

@mjilugu
Copy link

mjilugu commented 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.

@wx2228
Copy link

wx2228 commented Jul 16, 2017

still getting this error too.

@jseminck
Copy link
Contributor

jseminck commented Jul 16, 2017

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!

@wx2228
Copy link

wx2228 commented Jul 16, 2017

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

@andfelzapata
Copy link

it also wont check nextProps if componentWillReceiveProps is declared as an arrow function.

@ljharb
Copy link
Member

ljharb commented Jul 25, 2018

@andfelzapata would you file that as a separate issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants