Articles → REACT.JS → React fragment in the render method in react js

React fragment in the render method in react js






Purpose




Picture showing the render method in the jsx file

Click to Enlarge



Picture showing the error message when there are more than one parent

Click to Enlarge






How to use the “Render Fragment”?




import React from 'react';
import ReactDOM from 'react-dom'


const element = <React.Fragment>Hello World</React.Fragment>;

ReactDOM.render(element, document.getElementById('root'));



Benefits of using the “Render Fragment”









Use hooks for using Fragments




import React, { Fragment } from 'react';
import ReactDOM from 'react-dom';


const element = <Fragment>Hello World</Fragment>;

ReactDOM.render(
    element,
  document.getElementById('root')
);



Posted By  -  Karan Gupta
 
Posted On  -  Monday, August 2, 2021
 
Updated On  -  Monday, October 18, 2021

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250