Skip to main content

Fragment

Fragments represent smaller, reusable parts of a user interface within an application.

Ember

In Ember, you can return multiple elements naturally because Ember templates allow this without the explicit need for a wrapper component.

Text outside the list
<ul>
<li>Text inside the list</li>
</ul>

React

React components can only return one root node (doc). A Fragment is a lightweight wrapper that lets you group multiple elements without adding extra nodes to the DOM. This is particularly useful when a component needs to return multiple sibling elements.

function TextContainer() {
return (
<>
Text outside the list
<ul>
<li>Text inside the list</li>
</ul>
</>
)
}