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 insrc/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)
When to Use Fragments
Good Use Cases
When Not Needed
Key Prop Support
Fragments support thekey prop for lists:
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
Related APIs
h- Create virtual nodescreateElement- React-compatible node creationrender- Render components to DOM