Create own React.Fragment

iamandrewluca profile image Andrew Luca Updated on ・1 min read

Do you want to use React.Fragment in your app?
Are you using a React version lower than 16.2 that does not support fragments?
For some reason you cannot update React to support it?

Well I can tell you that you can create your own Fragment!

function Fragment(props) {
  return props.children;

Yeap is that simple.

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

function Fragment(props) {
  return props.children;

function App() {
  return (

ReactDOM.render(<App />, document.getElementById('root'));

Here is a demo if you want to play around.

Note that React 16.1 is used that does not support Fragment

Also if you take a look at Preact Fragment implementation, you will see exactly the function that we wrote above.


Posted on by:

iamandrewluca profile

Andrew Luca


All in Developer! ♣️♥️♠️♦️


markdown guide