Rules
no-void-elements-with-children
Full Name in eslint-plugin-react-dom
Full Name in @eslint-react/eslint-plugin
Presets
domrecommendedrecommended-typescriptrecommended-type-checked
Description
Disallow children in void DOM elements.
Self-closing HTML elements (e.g. <img />, <br />, <hr />) are collectively known as void DOM elements. React will give you a warning if you try to give these children:
Invariant Violation: img is a void element tag and must neither have children nor use dangerouslySetInnerHTML.
Examples
Failing
Passing
Implementation
See Also
no-dangerously-set-innerhtml
Warns when usingdangerouslySetInnerHTML.no-dangerously-set-innerhtml-with-children
Disallows DOM elements usingchildrenanddangerouslySetInnerHTMLat the same time.