Skip to content

Add React version into eslint-config-react-app #4538

Description

@UnableHead

Hello everyone,

Is this a bug report?

No

Situation

I'm working on a project that use React (react@15.6.2). I use react-scripts (1.0.11) to start and build my project.

According to my React version, I use some deprecated function:

These functions are deprecated in 16.3.0 of React.

Problems

Now, when I start or build my project, I get several warnings inside console and browser for this deprecated function.

Explanation

I try to understand why I got this message for the React 15.6.2 which are not concern by this warning. In fact, the package eslint-config-react-app@2.1.0 set the ESLint configuration for the actions of react-scripts.

The ESLint's plugin eslint-plugin-react have a rule: "react/no-deprecated" that created the warnings. This rule match on deprecated code, according to the configured React version number given in the ESLint config file. But, in this case, eslint-config-react-app does not define React version. So, as explain here: https://github.com/yannickcr/eslint-plugin-react#configuration, the default value is the latest React stable release.

That explain why I got warnings aiming React 16.3 in my project which use React 15.6.2.

Solution

I suggest as solution to define React version in the configuration file of eslint-config-react-app.

I resolve my problem on adding this:

settings: {
  react: {
    version: require('react').version
  }
},

inside the file index.js of eslint-config-react-app.

This solution could have some problems, especially, the package react is now mandatory (we could add a verification if package react exist before).

I know, that I could also "eject" my project and edit the config files, but I think this modification should be helpful for other users.

Discussion

In first time, I enjoy to know if my solution is correct on the content and the style. In second time, if people agree with me, I will create a pull request to integrate this modification inside the project.

Thanks for the reading. I hope that my post is clear enough.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions