Skip to content

unnecessaryFragments

Disallow unnecessary JSX fragments that wrap a single child or have no children.

✅ This rule is included in the jsx stylistic presets.

JSX fragments (<>...</> or <Fragment>...</Fragment>) are used to group multiple elements without adding extra nodes to the DOM. However, when a fragment wraps only a single child or has no children at all, it serves no purpose and adds unnecessary complexity to the code.

const
const element: any
element
= (
<>
<
any
div
>Hello</
any
div
>
</>
);
const
const element: any
element
= <>Hello</>;
const
const element: any
element
= <></>;
const
const element: any
element
= (
<
import Fragment
Fragment
>
<
any
div
>Hello</
any
div
>
</
import Fragment
Fragment
>
);

This rule is not configurable.

If your codebase has specific requirements where fragments are used consistently for stylistic reasons, you may want to disable this rule. However, removing unnecessary fragments is generally recommended to keep code concise and maintainable.

Made with ❤️‍🔥 around the world by the Flint team and contributors.