Login
Remember
Register
Ask a Question
Why fragments are better than container divs in ReactJS?Explain with Example?
0
votes
asked
Oct 29, 2023
in
ReactJS
by
DavidAnderson
Why fragments are better than container divs in ReactJS?Explain with Example?
reactjs-interview-questions-answers
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Oct 29, 2023
by
DavidAnderson
Below are the list of reasons to prefer fragments over container DOM elements,
Fragments are a bit faster and use less memory by not creating an extra DOM node. This only has a real benefit on very large and deep trees.
Some CSS mechanisms like
Flexbox
and
CSS Grid
have a special parent-child relationships, and adding divs in the middle makes it hard to keep the desired layout.
The DOM Inspector is less cluttered.
...