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.

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint