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

Add support for React 16 #1442

Closed
jseminck opened this issue Sep 19, 2017 · 11 comments
Closed

Add support for React 16 #1442

jseminck opened this issue Sep 19, 2017 · 11 comments

Comments

@jseminck
Copy link
Contributor

I think it would be great if this plugin would be ready with supporting all the new things that React 16 has to offer.

Currently I'm not sure exactly what would need to to be added though. The only thing I could think of was the componentDidCatch "lifecycle method" that got added. This should be added to a number of rules (prop-types, no-unused-prop-types, no-typos) and should only be checked when using React 16.

@ljharb
Copy link
Member

ljharb commented Sep 19, 2017

Adding these things only when the pragma is set to 16+ seems great; provided that the default is not changed prior to React 16 getting actually released.

If we're going to do this, let's take the opportunity to put the list of lifecycle methods in a single place :-)

@jseminck
Copy link
Contributor Author

jseminck commented Sep 26, 2017

Another thing we should test: since it's now possible to return an array from render(), but the array does require keys at the moment. So we should check whether the current rule react/no-array-index-key: Prevent using Array index in key props works for this case...

render() {
  // No need to wrap list items in an extra element!
  return [
    // Don't forget the keys :)
    <li key="A">First item</li>,
    <li key="B">Second item</li>,
    <li key="C">Third item</li>,
  ];
}

Edit: it works already. The rule was already smart enough to detect arrays!

@Dajust
Copy link

Dajust commented Oct 16, 2017

Hi, I just wanna find out how soon we might have this features!

Thanks for the great work!

@amannn
Copy link

amannn commented Nov 17, 2017

Another one I just stumbled across: react/sort-comp should recognize componentDidCatch as a lifecycle method in the order property.

@hozefaj
Copy link

hozefaj commented Feb 2, 2018

Getting error Expected 'this' to be used by class method 'componentDidCatch'. I guess until this is fixed, need to disable the check for this method.

@yannickcr
Copy link
Member

The following changes were merged to support React 16:

Is there still something missing for React 16 support ?

@yannickcr
Copy link
Member

Yes I saw that list, but from my point of view #1510 and #1682 are more about improvements of the component detection, which is tricky.

However I missed #1759 (confused it with the same problem in no-unused-prop-types, solved in #1681).

@TBBle
Copy link

TBBle commented Aug 30, 2018

Unless I'm misunderstanding something, https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/jsx-uses-react.js doesn't match for Fragments, and so a file with only a JSX Fragment and no other elements will raise

warning  'React' is defined but never used  no-unused-vars

Removing React does correctly raise

error  'React' must be in scope when using JSX  react/react-in-jsx-scope

due to d51b0cc (for #1758 mentioned above)

I observed this in eslint-plugin-react@7.8.2 pulled in from react-scripts@2.0.0-next.

I guess that the fix is simply to handle JSXOpeningFragment the way it handles JSXOpeningElement?

@alexzherdev
Copy link
Contributor

@ljharb I missed this in #1956, I’ll do another pass over the rules to double-check.

@ljharb
Copy link
Member

ljharb commented Apr 28, 2021

I'm pretty sure we have full support for React 16, and 17, so I'll close this. If anything's missing, please file a new issue.

@ljharb ljharb closed this as completed Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

8 participants