0 day streak
javascript / beginner
Snippet

React Fragments for Cleaner DOM

Fragments allow you to group a list of children without adding extra nodes to the DOM. You can use the explicit <Fragment> component or the short <> syntax.

snippet.js
javascript
1
2
3
4
5
6
7
8
9
10
import { Fragment } from 'react';
function ListItems() {
return (
<>
<li>Item 1</li>
<li>Item 2</li>
</>
);
}
react
Breakdown
1
<> ... </>
The shorthand syntax for a Fragment, wrapping multiple elements without a container div.