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 component is reported as unused when used in JSX

See original GitHub issue

I am getting no-unused-vars triggered when having an imported React component, and using it along with React.render with JSX Syntax.

Eslint v1.6.0

Reduced example:

import LabelsDropdown from './labels-dropdown';

// somewhere along the code in same file:
const $elm = this.$('.labels-filter')[0];
React.render(<LabelsDropdown hideDropdown={ this.removeComponent.bind($elm) } />, $elm);

And eslint lints this with: "LabelsDropdown" is defined but never used (no-unused-vars).

My .eslintrc config is:

{
    "ecmaFeatures": {
        "modules": true,
        "jsx": true
    },
    "env": {
        "es6": true,
        "browser": true,
        "node": true,
        "jquery": true,
        "mocha": true
    },
    "extends": "eslint:recommended",
    "rules": {
        "arrow-parens": [1, "as-needed"],
        "arrow-spacing": [1, { "before": true, "after": true }],
        "brace-style": [2, "1tbs"],
        "comma-dangle": [0, "always-multiline"],
        "curly": [2, "all"],
        "dot-notation": [1, { "allowKeywords": false, "allowPattern": "" }],
        "jsx-quotes": [1, "prefer-double"],
        "no-const-assign": [2],
        "no-unused-vars": [1, {"vars": "all", "args": "after-used"}],
        "no-use-before-define": [1],
        "prefer-const": [1],
        "prefer-spread": [1],
        "prefer-template": [0],
        "quotes": [1, "single"],
        "yoda": [1, "never"],
        "semi": [1, "always"],
        "semi-spacing": [1, {"before": false, "after": true}]
    }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
lo1tumacommented, Nov 29, 2015

@just-boris that’s not correct. JSX can and actually is used without react. Examples: msx, mercury-jsx, jsx-dom.

0reactions
just-boriscommented, Nov 29, 2015

At the bottom of file 😃

Ok, I got this. It can be as is, unless more people come to the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'React' is defined but never used - Stack Overflow
React is used to handle JSX and creation of React component ... simply means your project has eslint configured to catch unused variables....
Read more >
Assigned a Value but Never Used | React JS Debugging
In react component I want to display a name but I want to read it from the ... Assigned a Value but Never...
Read more >
eslint-plugin-react - npm
Start using eslint-plugin-react in your project by running `npm i ... Regex for Component Factory to use, // default to "createReactClass" ...
Read more >
React Without JSX
Using React without JSX is especially convenient when you don't want to set up compilation in your build environment. Each JSX element is...
Read more >
Why Did And Don't You Need To Import React - Chak Shun Yu
But why was this seemingly unused import when creating React ... To create React components, the standard is to use JSX which is...
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