forlooptanzania / ride-my-way

Car pooling app (of developers) by developers for developers in Tanzania
22 stars 6 forks source link

Best practice is using <React.Fragment> #33

Open chrisoemma opened 5 years ago

chrisoemma commented 5 years ago

Hello people,

I just come across this post which explains why we should not use pointless div just to close the elements in one tag. Chere it here https://www.barrymichaeldoyle.com/fragment/

Let's all be professional developers.

Cheers

nelsonfrank commented 5 years ago

React. Fragment (Uses)

React.fragment is very important if you are trying to render multiple child components, All your components supposed to be inside of React.Fragment tag

<React.Fragment>
    <child1 />
    <child2 />
    <child3 />
</React.Fragment>

or

<>
    <child1 />
    <child2 />
    <child3 />
</>

Cheers

BenMaruchu commented 5 years ago

I advice using fragment and also you don't have to call React.Fragment just import React, {Fragment} from 'react'