The Indiscriminate Spread Antipattern
What you'll learn: Why spreading all props without thinking creates unclear, hard-to-debug components.
The Problem with Blind Spreading
You've learned that spreading props ({...props}) can be useful when wrapping native elements. But there's a dangerous pattern: indiscriminately spreading every prop you receive without knowing what they are.
// ❌ BAD: What props does this accept? Nobody knows!
function MyButton(props) {
return <button {...props}>Click me</button>;
}
// What happens here?
<MyButton
onClick={handleClick}
className="btn"
somethingWeird={true}
data-random="???"
/>
Why This Is a Code Smell
1. Unclear API
Other developers (including future you) can't tell what props your component actually accepts. Is somethingWeird intentional? Will it break things?
2. Accidental Prop Forwarding
You might accidentally pass props that override things you didn't mean to change, or forward props that have no business being on that element.
3. Debugging Nightmare
When something breaks, you have to trace through every possible prop that might have been passed. You've created a "mystery component."
The Better Approach
Be explicit about what you accept:
// ✅ GOOD: Clear API, intentional forwarding
function MyButton({ onClick, className, ...rest }) {
return (
<button
onClick={onClick}
className={`my-btn ${className}`}
{...rest}
>
Click me
</button>
);
}
Now you've explicitly handled the props you care about, and only unknown props get spread.
Key Takeaway: Blindly spreading all props makes your component API unclear and creates debugging pain. Extract and handle the props you care about explicitly before spreading the rest.