eSlint未使用的变量(反应)

问题描述 投票:0回答:1

为什么Eslint不断抱怨未使用的React Prop,此代码没有任何问题。按预期工作。 “图标”道具用于代码。

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> );

error image

BELOW是Eslint配置文件,它是由Vite生成的。根本没有更改,只需使用默认值。

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 }, ], }, }, ]

	
reactjs visual-studio-code eslint
1个回答
0
投票

'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],

在有未使用的变量时,这意味着要丢下错误。
仅从对象中删除该键,您应该很好。 ruledef

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.