EasyReact Fundamentals📖 Theory Question

What are React Fragments and when do you need them?

💡

Hint

<></> lets you return multiple elements without adding an extra DOM node

Full Answer

Fragments let you group multiple elements without adding an extra DOM wrapper node.

// ❌ Extra div pollutes the DOM
function TableRow() {
  return (
    
{/* invalid inside */} Name Age
); } // ✅ Fragment — no DOM node added function TableRow() { return ( <> Name Age ); } // Keyed fragments — use the long form syntax (shorthand doesn't support key) function List({ items }) { return items.map(item => (
{item.term}
{item.description}
)); }
💡 Fragments matter most in table structures (tr/td/th must be direct children) and flexbox/grid layouts where an extra wrapper breaks the CSS.

More React Fundamentals Questions

EasyWhat is React and what problem does it solve?EasyWhat is JSX and how does it work under the hood?EasyWhat is the Virtual DOM and how does reconciliation work?EasyWhat is the difference between a controlled and uncontrolled component?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint