noVoidElementsWithChildren
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/correctness/noVoidElementsWithChildren
Since: v1.0.0
Sources:
- Same as:
react/void-dom-elements-no-children
This rules prevents void elements (AKA self-closing elements) from having children.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.jsx:1:1 lint/correctness/noVoidElementsWithChildren FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ br is a void element tag and must not have children.
> 1 │ <br>invalid child</br>
│ ^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the children.
1 │ <br>invalid·child</br>
│ --------------- --
code-block.jsx:1:1 lint/correctness/noVoidElementsWithChildren FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ img is a void element tag and must not have children.
> 1 │ <img alt=“some text” children={“some child”} />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the children.
1 │ <img·alt=“some·text”·children={“some·child”}·/>
│ ------------------------
code-block.js:1:1 lint/correctness/noVoidElementsWithChildren FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ img is a void element tag and must not have children.
> 1 │ React.createElement(‘img’, {}, ‘child’)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the children.
1 │ React.createElement(‘img’,·{},·‘child’)
│ -------