react/jsx-no-useless-fragment
eslint-plugin-react
Safe autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/jsx-no-useless-fragment": "error",
},
},
];<>{foo}</>
<><Foo /></>
<p><>foo</></p>
<></>
<Fragment>foo</Fragment>
<React.Fragment>foo</React.Fragment>
<section>
<>
<div />
<div />
</>
</section>
{showFullName ? <>{fullName}</> : <>{firstName}</>}{foo}
<Foo />
<>
<Foo />
<Bar />
</>
<>foo {bar}</>
<> {foo}</>
const cat = <>meow</>
<SomeComponent>
<>
<div />
<div />
</>
</SomeComponent>
<Fragment key={item.id}>{item.value}</Fragment>
{showFullName ? fullName : firstName}Examples from the ESLint documentation.
react/jsx-no-useless-fragment
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/jsx-no-useless-fragment": "error",
},
},
];react/jsx-no-useless-fragment
react plugin · pedantic
{
"plugins": [
"react"
],
"rules": {
"react/jsx-no-useless-fragment": "error"
}
}complexity/noUselessFragments
complexity · since 1.0.0
{
"linter": {
"rules": {
"complexity": {
"noUselessFragments": "error"
}
}
}
}Disallow void DOM elements (e.g. <img />, <br />) from receiving children
Disallow usage of button elements without an explicit type attribute
Disallow usage of Array index in keys
Disallow usage of dangerous JSX properties
Disallow usage of referential-type variables as default param in functional component
Disallow missing props validation in a React component definition