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

I have the error 'React' is defined but never used no-unused-vars for *.jsx files with jsx markup. Here is some of my environment:

  1. package.json
"react": "^16.0.0"
"babel-eslint": "^8.0.1"                                                                                                                                                                                  
"eslint": "^4.8.0"                                                                                                                                                                                        
"eslint-config-airbnb": "^15.1.0"                                                                                                                                                 "eslint-import-resolver-webpack": "^0.8.3"                                                                                                                                                                
"eslint-loader": "^1.9.0"                                                                                                                                                                                 
"eslint-plugin-import": "^2.7.0"                                                                                                                                                                          
"eslint-plugin-jsx-a11y": "^5.1.1"                                                                                                                                                                        
"eslint-plugin-react": "^7.4.0"                                                                                                                                                     
  1. .eslintrc.json
{                                                                                                                          
  "env": {                                                                                                                 
    "browser": true                                                                                                        
  },                                                                                                                       
  "extends": [                                                                                                             
    "airbnb",                                                                                                              
    "plugin:react/recommended"                                                                                             
  ],                                                                                                                       
  "parser": "babel-eslint",                                                                                                
  "plugins": [                                                                                                             
    "import",                                                                                                              
    "react",                                                                                                               
    "jsx-a11y"                                                                                                             
  ],                                                                                                                       
  "rules": {                                                                                                               
    "comma-dangle": ["error", "never"],                                                                                    
    "max-len": ["error", 120],                                                                                             
    "no-unused-vars": ["error", { "args": "none" }],                                                                       
    "react/prop-types": "off"                                                                                              
  },                                                                                                                       
  "settings": {                                                                                                            
    "import/resolver": {                                                                                                   
      "webpack": {                                                                                                         
        "config": "config/webpack/development.js"                                                                          
      }                                                                                                                    
    }                                                                                                                      
  }                                                                                                                        
} 

How can I fix it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
evserykhcommented, Oct 4, 2017

Oh, sorry, my bad ☹️ I understood what’s wrong. As I use React 0.16 I have some draft components like this:

import React from 'react';
const Foo = () => 'Foo';
export default Foo;

The error is quite logical. When I change markup to <div>Foo</div> all works fine

3reactions
evserykhcommented, Oct 4, 2017

@ljharb I’ve just tried adding "react/jsx-uses-vars": "error" and "react/jsx-uses-react": "error" rules but it didn’t work

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint with React gives `no-unused-vars` errors
I have my eslintrc extending plugin:react/recommended , but it still gives me this warning. I think it's because I'm using React in a...
Read more >
'React' is defined but never used no-unused-vars · Issue #11183
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'...
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 >
no-unused-vars - ESLint - Pluggable JavaScript Linter
Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take...
Read more >
eslint-plugin-no-unused-vars-rest - npm package - Snyk
An enhanced version of the ESLint core rule no-unused-vars with allowances ... eslint-plugin-react ... Error 'extra' is defined but never used. return rest;....
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