jsx-no-useless-fragment
UnreleasedConfiguration
Rule Details
Disallow unnecessary fragments. A fragment is redundant if it contains only one child, or if it is the child of an HTML element, and is not a keyed fragment.
Both fragment spellings are checked: the <>…</> shorthand and the long form
named by the react / fragment shared settings (<Fragment> and
<React.Fragment> by default). A @jsx annotation in the file — such as
/** @jsx Preact.h */ — renames the object half of the long form for that file
and takes precedence over settings.react.pragma.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allowExpressions(default:false): whentrue, a fragment wrapping a single expression is allowed. This is useful in TypeScript, wherestringdoes not satisfy the expectedJSX.Elementreturn type and wrapping the value in a fragment is a common workaround.
Examples of correct code when allowExpressions is true:
Note that allowExpressions only relaxes the "needs more children" check — a
fragment passed to an HTML element is still reported.