Articles → REACT.JS → React Fragment In The Render Method In React Js
React Fragment In The Render Method In React Js
Purpose
Click to Enlarge
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”
- Fragment is faster
- DOM is less cluttered
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')
);