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: support shouldComponentUpdate nextProps #1213

Closed
xareelee opened this issue May 20, 2017 · 8 comments
Closed

no-unused-prop-types: support shouldComponentUpdate nextProps #1213

xareelee opened this issue May 20, 2017 · 8 comments

Comments

@xareelee
Copy link

type LoginMsgContainerProps = {
  getMsgCodeErrorMsg?: string,
};

class LoginMsgContainer extends React.Component {

  props: LoginMsgContainerProps;

  shouldComponentUpdate(props: LoginMsgContainerProps) {
    if (props.getMsgCodeErrorMsg && props.getMsgCodeErrorMsg.length > 0) {
      this.toast.show(props.getMsgCodeErrorMsg);
    }
  }

  ...
}

I only use prop getMsgCodeErrorMsg in the method shouldComponentUpdate, but the linter raises a react/no-unused-prop-types error (false positive).

@ljharb
Copy link
Member

ljharb commented May 20, 2017

shouldComponentUpdate takes nextProps - what happens if you name the argument that?

@xareelee
Copy link
Author

xareelee commented May 20, 2017

@ljharb changing the param name doesn't help.

The linter reports the error on the line where I declare the type:

type LoginMsgContainerProps = {
  getMsgCodeErrorMsg?: string,   // The linter raises the error on this line and column 24 
};

  18:24  error  'getMsgCodeErrorMsg' PropType is defined but prop is never used
                                  react/no-unused-prop-types

I use the same type for both React component's props and the method shouldComponentUpdate ().

@ljharb
Copy link
Member

ljharb commented May 20, 2017

If instead of a Flow type, you used standard .propTypes, do you get the same error?

@xareelee
Copy link
Author

xareelee commented May 20, 2017

@ljharb yes, get the same error with .propTypes. I did not find that.

It produces both react/require-default-props and react/no-unused-prop-types errors, no matter using flowtype or .propTypes.

I reported react/require-default-props error on a separated issue #1212.

@ljharb
Copy link
Member

ljharb commented May 20, 2017

Thanks, it seems like we need to make no-unused-prop-types work with shouldComponentUpdate.

@ljharb ljharb changed the title Only using a prop in lifecycle methods raises a react/no-unused-prop-types error no-unused-prop-types: support shouldComponentUpdate nextProps May 20, 2017
@xareelee
Copy link
Author

@ljharb OK, thanks.

Any workaround about this bug for now?

@ljharb
Copy link
Member

ljharb commented May 20, 2017

The workaround would be an eslint override comment.

@ljharb
Copy link
Member

ljharb commented Jun 2, 2017

#1232 hopefully has solved this; we can reopen after the next release if not.

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

No branches or pull requests

2 participants