What are fragments in React and why are they useful?
Instruction: Explain the concept of fragments in React and provide scenarios where they are beneficial.
Context: This question explores the candidate's knowledge of React fragments and their use cases, particularly in avoiding unnecessary DOM elements.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
A Fragment groups children in the React tree without creating a wrapper DOM element. This helps preserve a parent's intended layout or valid HTML structure when an extra div would be inappropriate.
For example, cells must be inside a table row...