eslint-plugin-react-hooks - This feature is available in the latest RC version

eslint-plugin-react-hooks 提供 ESLint 规则以强制执行 React 规则

这个插件可以帮助你在构建时捕捉违反 React 规则的情况,确保你的组件和钩子遵循 React 的正确性和性能规则。lint检查既包括基本的 React 模式(如 exhaustive-deps 和 rules-of-hooks),也包括 React 编译器标记的问题。React 编译器的诊断信息会自动通过这个 ESLint 插件显示,即使你的应用还没有采用该编译器,也可以使用这些诊断信息。

🌐 This plugin helps you catch violations of React’s rules at build time, ensuring your components and hooks follow React’s rules for correctness and performance. The lints cover both fundamental React patterns (exhaustive-deps and rules-of-hooks) and issues flagged by React Compiler. React Compiler diagnostics are automatically surfaced by this ESLint plugin, and can be used even if your app hasn’t adopted the compiler yet.

注意

当编译器报告诊断信息时,这意味着编译器能够静态检测到不被支持或违反 React 规则的模式。当它检测到这一点时,它会自动跳过这些组件和钩子,同时保持你的应用的其余部分已编译。这确保了不会破坏应用的安全优化的最佳覆盖率。

这对代码检查的意义在于,你不需要立即修复所有违规问题。可以按照自己的节奏处理它们,以逐步增加优化组件的数量。

🌐 Recommended Rules

这些规则包含在 eslint-plugin-react-hooks 中的 recommended 预设中:

🌐 These rules are included in the recommended preset in eslint-plugin-react-hooks: