noChildrenProp
Diagnostic Category: lint/correctness/noChildrenProp
Since: v1.0.0
Sources:
- Same as:
react/no-children-prop
Description
Section titled DescriptionPrevent passing of children as props.
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
Section titled ExamplesInvalid
Section titled 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
How to configure
Section titled How to configure{ "linter": { "rules": { "correctness": { "noChildrenProp": "error" } } }}