React

Fragments

#react

We can’t return multiple values aka JSX code, that’s why we need to wrap it inside a parent element. So instead of inserting an extra div in HTML code, use React Fragments.

<> </>

This shorthand syntax for <React.Fragment></React.Fragment>

allows you to group a list of children without adding extra nodes to the DOM. It effectively serves as an invisible wrapper for your mapped elements.

On this page