question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

When i run eslint on my code, I get the error: 'React' is defined but never used no-unused-vars when I remove import ‘React’ from ‘react’ I get the error 'React' must be in scope when using JSX

I tried enabling the rules below but still receive the error. “react/jsx-uses-react”: 1, “react/jsx-uses-vars”: 1, “react/react-in-jsx-scope”: 1

Can someone help me check if my configurations are correct, if I’m not overriding anything?

{
  "parser": "babel-eslint",
  "extends": [
    "eslint:recommended",
    "airbnb",
    "plugin:flowtype/recommended"
  ],
  "plugins": [
    "babel",
    "react",
    "flowtype"
  ],
  "rules": {
    "react/jsx-uses-react": 1,
    "react/jsx-uses-vars": 1,
    "react/react-in-jsx-scope": 1,
  
    // Indent with 4 spaces
    "indent": [
      "error",
      4
    ],
    // Indent JSX with 4 spaces
    "react/jsx-indent": [
      "error",
      4
    ],
    // Indent props with 4 spaces
    "react/jsx-indent-props": [
      "error",
      4
    ],
    // TODO: Remove all of these exceptions
    // We have code that violates each one of these rules.
    // We should fix the style then remove the rules when we can.
    "consistent-return": "off",
    "flowtype/no-types-missing-file-annotation": "off",
    "import/extensions": "off",
    "import/no-unresolved": "off",
    "import/no-named-as-default": "off",
    "import/no-named-as-default-member": "off",
    "import/prefer-default-export": "off",
    "react/default-props-match-prop-types": "off",
    "react/forbid-prop-types": "off",
    "react/jsx-closing-tag-location": "off",
    "react/jsx-filename-extension": "off",
    "react/no-string-refs": "off",
    "react/no-unused-prop-types": "off",
    "react/no-unused-state": "off",
    "react/prefer-stateless-function": "off",
    "react/prop-types": "off",
    "react/require-default-props": "off",
    "react/sort-comp": "off",
    "max-len": "off",
    "no-case-declarations": "off",
    "no-console": "off",
    "no-mixed-operators": "off",
    "no-nested-ternary": "off",
    "no-shadow": "off",
    "no-use-before-define": "off",
    "no-underscore-dangle": "off",
    "no-unused-expressions": "off",
    "prefer-promise-reject-errors": "off"
  },
  "env": {
    "jest": true
  },
  "globals": {
    "fetch": false,
    "Response": false,
    "React": true
  }
}

I am using these versions in package.json: devDependencies

      "eslint-config-airbnb": "16.1.0",
      "eslint-plugin-babel": "^5.1.0",
      "eslint-plugin-flowtype": "^2.46.1",
      "eslint-plugin-react": "^7.9.1",

dependencies

  "react": "16.0.0",
  "react-native": "0.50.4",

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
not-an-aardvarkcommented, Dec 12, 2018

You might need to enable the react/jsx-uses-react rule.

0reactions
eslint-deprecated[bot]commented, Jan 17, 2019

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint with React gives `no-unused-vars` errors
When I run ESLint, the linter returns no-unused-vars errors for each React component. I'm assuming it's not recognizing that I'm using JSX or ......
Read more >
Assigned a Value but Never Used | React JS Debugging
Assigned a Value but Never Used | No Unused Vars | React JS Debugging | Eslint Warnings & Errors.
Read more >
JavaScript : ESLint with React gives `no-unused-vars` errors
JavaScript : ESLint with React gives ` no - unused - vars ` errors [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ]...
Read more >
no-unused-vars - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
UseState is defined but never used no-unused-vars : r/reactjs
This is a linting error. Importing stuff requires work. If you import something but never use it, resources go to waste for nothing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found