Skip to content

noChildrenProp

¥Summary

¥How to configure

biome.json
{
"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