React component is reported as unused when used in JSX
See original GitHub issueI 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:
- Created 8 years ago
- Comments:8 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@just-boris that’s not correct. JSX can and actually is used without react. Examples: msx, mercury-jsx, jsx-dom.
At the bottom of file 😃
Ok, I got this. It can be as is, unless more people come to the issue.