Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 867 Bytes

jsx-no-useless-fragment.md

File metadata and controls

54 lines (36 loc) · 867 Bytes

Disallow unnecessary fragments (react/jsx-no-useless-fragment)

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.

Fixable: This rule is sometimes automatically fixable using the --fix flag on the command line.

Rule Details

The following patterns are considered warnings:

<>{foo}</>

<><Foo /></>

<p><>foo</></p>

<></>

<Fragment>foo</Fragment>

<React.Fragment>foo</React.Fragment>

<section>
  <>
    <div />
    <div />
  </>
</section>

The following patterns are not considered warnings:

<>
  <Foo />
  <Bar />
</>

<>foo {bar}</>

<> {foo}</>

const cat = <>meow</>

<SomeComponent>
  <>
    <div />
    <div />
  </>
</SomeComponent>

<Fragment key={item.id}>{item.value}</Fragment>