noChildrenProp
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noChildrenProp¥Diagnostic Category:
lint/correctness/noChildrenProp -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
-
¥Same as
react/no-children-prop
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noChildrenProp": "error" } } }}¥Description
防止将子组件作为 props 传递。
¥Prevent passing of children as props.
使用 JSX 时,子元素应嵌套在开始和结束标记之间。不使用 JSX 时,应将子节点作为附加参数传递给 React.createElement。
¥When using JSX, the children should be nested between the opening and closing tags.
When not using JSX, the children should be passed as additional arguments to React.createElement.
¥Examples
¥Invalid
<FirstComponent children={'foo'} />code-block.jsx:1:17 lint/correctness/noChildrenProp ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid passing children using a prop
> 1 │ <FirstComponent children={‘foo’} />
│ ^^^^^^^^
2 │
ℹ The canonical way to pass children in React is to use JSX elements
React.createElement('div', { children: 'foo' });code-block.js:1:30 lint/correctness/noChildrenProp ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid passing children using a prop
> 1 │ React.createElement(‘div’, { children: ‘foo’ });
│ ^^^^^^^^
2 │
ℹ The canonical way to pass children in React is to use additional arguments to React.createElement
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号