react/no-find-dom-node Correctness
作用
此规则禁止使用 findDOMNode,它已于 2018 年被弃用,并在 React 19 中移除。
为什么这很糟糕?
findDOMNode 是一个用于访问底层 DOM 节点的后门。 在大多数情况下,不建议使用这个后门,因为它破坏了组件抽象。 它已经被弃用多年,并且已 在 React 19 中被 React 完全移除。
不应使用它。
示例
以下是此规则的错误代码示例:
jsx
class MyComponent extends Component {
componentDidMount() {
findDOMNode(this).scrollIntoView();
}
render() {
return <div />;
}
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["react"],
"rules": {
"react/no-find-dom-node": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["react"],
rules: {
"react/no-find-dom-node": "error",
},
});bash
oxlint --deny react/no-find-dom-node --react-plugin版本
此规则是在 v0.0.15 中添加的。
