React 16 Fragments Misuse

286 Views Asked by At

In React version 16, Fragments were implemented. I love using them!

My question is, what if I use Fragments unnecessarily. Does it matter? Can I stick them in as boilerplate for my code in-case I want to add adjacent elements later or is that bad practice.

And if it is bad practice. Why? Since they don't get rendered in the DOM anyway. Does it matter if I add it or not?

It just feels wrong and I want some clarity there.

1

There are 1 best solutions below

0
On BEST ANSWER

The use of the Fragment tag will only affect the bundle size of the project in a very minor way.

Best practice would be to only use a Fragment when it is necessary.