Shorthand Syntax for Fragments

React has a shorthand syntax to represent React fragments, that is by replacing “<React.fragment>” with empty angular brackets
“<>…</>” .

Note: Shorthand syntax cannot accept keys or attributes.

Javascript
// App.js

import React from "react";

function App() {
    return (
        <>
            <FirstComponent />
            <SecondComponent />
            <ThirdComponent />
        </>
    );
}
export default App;

React Fragments: Eliminating Unnecessary Divs in the DOM

React Fragments function as wrapper elements that help us to group multiple components without using any additional DOM node. Fragments in React avoid unnecessary div tags or containers which helps in maintaining an efficient DOM structure.

Table of Content

  • What are React Fragments?
  • Shorthand Syntax for Fragments
  • React Fragments and their impact on DOM structure
  • React Fragments vs Regular HTML Elements

Similar Reads

What are React Fragments?

React Fragments are placeholders in React that let you group multiple components and JSX elements without adding extra unnecessary

elements to the DOM. Instead of always wrapping your components in a

Shorthand Syntax for Fragments

React has a shorthand syntax to represent React fragments, that is by replacing “” with empty angular brackets “<>…” ....

React Fragments and their impact on DOM structure

React Fragments helps in avoiding unecessary div’s in the DOM. These unecessary div’s leads to enlarged DOM tree that creates a negative impact on the user experience and on the rendering speed of a page. Fragments has no visual representation on DOM, unlike “div” tags are represented by a block....

React Fragments vs Regular HTML Elements

React Fragments : React Fragments allow you to return multiple components without the involvement of an additonal DOM node (“div “). Fragments have the feature of passing keys and attributes, but it is not possible to use any styling property with fragments. Fragments consume less memory compared to regular HTML elements, it helps in improvising the rendering speed and also in maintaining a proper DOM structure....