MediumAdvanced Patterns📖 Theory Question

What is prop spreading and when is it an anti-pattern?

💡

Hint

{...props} forwards all props — useful for wrapper components but can pass wrong props to DOM elements

Full Answer

// ✅ Legitimate use — forwarding unknown props to underlying element
function Button({ variant, className, ...rest }) {
  return (
    
💡 Always destructure custom props before spreading. "Rest" in a component should only contain valid HTML attributes for the element it spreads onto.

More Advanced Patterns Questions

MediumWhat is Error Boundary and how do you implement one?MediumWhat is the Suspense pattern and data fetching with it?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint