DEV Community

Discussion on: Beginner's experience with React - a shout for feedback

Collapse
 
sergiodxa profile image
Sergio Daniel Xalambrí

This idea of React has to return a div that contains other things and all results in too many divs! The markup has empty divs just to return two component togethers! So what's the best way to handle this?

React has something called React.Fragment for exactly this reason. Read more on reactjs.org/docs/fragments.html

Collapse
 
devshehata profile image
Mahmoud Shehata

Yup that looks great! will start using that for sure! Thanks for the tip

Collapse
 
amorriscode profile image
Anthony M.

There is an excellent shorthand for fragments too!

const Component = () => (
<>
  <span>
    Hello World
  </span>
</>
);