Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Component is defined but never used" for eslint in react?

This is the config i have for eslint in .eslintrc.json file:

 {
        "env": {
            "browser": true,
            "commonjs": true,
            "es6": true
        },
        "extends": "eslint:recommended",
        "parserOptions": {
            "ecmaVersion": 6,
            "ecmaFeatures": {
                "experimentalObjectRestSpread": true,
                "jsx": true
            },
            "sourceType": "module"
        },
        "plugins": [
            "react"
        ],
        "rules": {
            "react/jsx-uses-react": "error",
            "react/jsx-uses-vars": ["error"],
            "indent": 0,
            "linebreak-style": [
                "error",
                "windows"
            ],
            "quotes": [
                "error",
                "single"
            ],
            "semi": [
                "error",
                "always"
            ]
        },
        "settings": {
        "react": {
          "pragma": "React",
          "version": "15.0"
        }
      }
    }

This is the app.jsx from the react workspace below:

 import React, { Component } from 'react';

    class App extends React.Component {
      render () {
        return(
          <h1>Hello Newbies</h1>
        );
      }
    }

    export default App;

I am getting error from eslint 'Component' is defined but never used. I can not fix this by doing anything so far but digging the web. How can i fix this error? Help would be very much appreciated.

like image 754
ShocKwav3_ Avatar asked Apr 23 '17 23:04

ShocKwav3_


2 Answers

Try

class App extends Component {
like image 139
Anthony Kong Avatar answered Sep 28 '22 03:09

Anthony Kong


Option 1: You don't need to import {Component} since you extends React.component and React is already imported.

Option 2: You can extend your App with Component instead of React.Component

like image 24
williamwmy Avatar answered Sep 28 '22 03:09

williamwmy