DEV Community

Discussion on: Are you giving the proper sense to React.Fragment?

Collapse
 
cullophid profile image
Andreas Møller • Edited

I much prefer this version:

return items && 
        <ul>
        { items.map(i => <li key={i}>{i}</li>) }
      </ul>;
Enter fullscreen mode Exit fullscreen mode
  • The logic is inlined so you don't have to jump between component when reading the code.

  • You won't have ever new dev on your team asking you why you are returning and empty fragment.

The final example looks more "clean", but what actually happens is that you have to jump around in the file a lot to understand what is happening.

Collapse
 
codbugs profile image
Coding Bugs

Agree with your last point. We should balance the benefits of creating components and get a complex solution from a file structure point of view.

Collapse
 
cullophid profile image
Andreas Møller

And we need to stop promoting ideas like DRY and Single Responsibility Principle, which are at best pointless and at worst harmful.