admin管理员组文章数量:1391947
Why is ESLint constantly complaining about unused react prop, this code doesn't have any issue. Works as expected. The "Icon" prop is used withing the code.
const PageLink = ({ icon: Icon, title, ...props }) => (
<Link
{...props}
className={cn(
"p-2 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-center",
"flex gap-2 justify-center items-center"
)}
>
<Icon className="size-4" />
{title}
</Link>
);
Below is the ESLint config file, it was generated by Vite. Not changed at all, just using the default.
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...reactHooks.configs.recommended.rules,
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
Why is ESLint constantly complaining about unused react prop, this code doesn't have any issue. Works as expected. The "Icon" prop is used withing the code.
const PageLink = ({ icon: Icon, title, ...props }) => (
<Link
{...props}
className={cn(
"p-2 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-center",
"flex gap-2 justify-center items-center"
)}
>
<Icon className="size-4" />
{title}
</Link>
);
Below is the ESLint config file, it was generated by Vite. Not changed at all, just using the default.
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...reactHooks.configs.recommended.rules,
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
Share
Improve this question
edited Mar 14 at 7:44
Sadiq Salau
asked Mar 14 at 5:48
Sadiq SalauSadiq Salau
1296 bronze badges
2
|
1 Answer
Reset to default 0Given your eslint file, you have the rule:
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
which means throw an error when there are unused variables.
Just remove that key from the object and you should be good.
Rule def
本文标签: reactjsESLint unused variable (React)Stack Overflow
版权声明:本文标题:reactjs - ESLint unused variable (React) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744672385a2618901.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
no-unused-vars
or please share the file here – Tushar Shahi Commented Mar 14 at 6:06