-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Update no-unused-prop-types rule for new React class component lifecycles #1681
Conversation
lib/rules/no-unused-prop-types.js
Outdated
'componentDidUpdate', | ||
'componentWillReceiveProps', | ||
'componentWillUpdate', | ||
'getDerivedStateFromProps', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these new methods should only be checked if the React version pragma from settings is >= 16.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. Thanks for pointing that out.
9b47c5b
to
c0c7ce0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Can we get this PR merged ? |
I checked the PR and it works. Could you please merge this PR? |
The upcoming React 16.3 release will make a couple of changes to the class component lifecycles:
componentWillMount
,componentWillReceiveProps
, andcomponentWillUpdate
are being aliased toUNSAFE_componentWillMount
,UNSAFE_componentWillReceiveProps
, andUNSAFE_componentWillUpdate
and a new static lifecycle,getDerivedStateFromProps
, is being added.For background information, see RFC 6.
When running codemods at Facebook to rename these lifecycles, I noticed that it caused a couple of false positives with the
react/no-unused-prop-types
lint rule since that rule was not yet aware of the lifecycle changes. I think this PR corrects that. I added a couple of sanity check tests (which failed before my changes) to verify this.