Skip to main content
A special component that allows grouping multiple children without adding extra DOM nodes.

Signature

Type Definition

Description

Fragment is a built-in component that renders its children directly without creating a wrapper DOM element. It’s useful when you need to return multiple elements from a component but don’t want to add an extra <div> or other container to the DOM.

Implementation

The Fragment is implemented in src/create-element.js:77 as a simple pass-through function:

Usage Examples

Basic Fragment

Short Syntax

Conditional Rendering

Lists and Keys

Multiple Return Elements

With Map

Nested Fragments

JSX Configuration

To use the <> short syntax, configure your JSX transform: TypeScript (tsconfig.json)
Babel (.babelrc)
Import Configuration

When to Use Fragments

Good Use Cases

When Not Needed

Key Prop Support

Fragments support the key prop for lists:
Note: Fragments do not support other props besides key and children.

Differences from Wrapper Elements

Performance Considerations

  • Fragments have zero overhead - they don’t create DOM nodes
  • No CSS/layout impact from wrapper elements
  • Slightly faster than rendering a wrapper element
  • Ideal for keeping DOM structure clean and semantic
  • h - Create virtual nodes
  • createElement - React-compatible node creation
  • render - Render components to DOM