noChildrenProp
诊断类别:lint/correctness/noChildrenProp
¥Diagnostic Category: lint/correctness/noChildrenProp
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
react/no-children-prop
¥Same as:
react/no-children-prop
防止将子组件作为 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
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
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