我有一个Reaction项目,并且已经使用Reaction路由V6附带的钩子useNavigate
创建了一个定制钩子.自定义挂钩工作得很好,现在我需要阻止这个项目中的开发人员使用本地的useNavigate
挂钩.我按如下方式配置了我的ESLint脚本.并且我已经安装了依赖项"eslint-plugin-action-hooks"The problem is, I'm getting the error "[eslint] Failed to load plugin 'no-react-hooks' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-no-react-hooks'"
.eslintrc.json
{
"extends": [
"react-app",
"plugin:no-react-hooks/recommended"
],
"plugins": ["react", "no-react-hooks"],
"rules": {
"no-react-hook/use-navigate": "error"
}
}
Eslint-plugin-no-react-hooks.js
module.exports = {
rules: {
'use-navigate': {
meta: {
type: 'problem',
docs: {
description: 'Prevent usage of the useNavigate hook',
category: 'Best Practices',
recommended: true,
},
},
create(context) {
return {
ImportDeclaration(node) {
if (
node.source.value === 'react-router-dom' &&
node.specifiers.some(
(specifier) => specifier.imported.name === 'useNavigate',
)
) {
context.report({
node: node,
message:
'Do not use the useNavigate hook. Instead, use "useCustomNavigate"',
});
}
},
};
},
},
},
};
我怎么才能解决这个问题?