react/jsx-props-no-spread-multi Correctness
它的作用
强制任何唯一表达式只展开一次。
这为什么不好?
通常,重复展开同一个表达式表明存在错误,因为两个展开之间的任何属性都可能被覆盖,而这并非本意。 即使不是这种情况,这也会导致不必要的计算。
示例
此规则的错误代码示例:
jsx
<App {...props} myAttr="1" {...props} />此规则的正确代码示例:
jsx
<App myAttr="1" {...props} />
<App {...props} myAttr="1" />如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["react"],
"rules": {
"react/jsx-props-no-spread-multi": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["react"],
rules: {
"react/jsx-props-no-spread-multi": "error",
},
});bash
oxlint --deny react/jsx-props-no-spread-multi --react-plugin版本
此规则是在 v0.7.2 中添加的。
