Course contentsShow
← React
Lesson 265 of 2,3968. Props PatternsFree lesson

When to Spread vs Explicit Props

Decision framework: spread for HTML passthroughs and lib wrappers, explicit props for component boundaries.

When to Spread vs Explicit Props

What you'll learn: A simple decision framework for choosing between spreading props and defining them explicitly.

The Decision Framework

You've now seen both patterns—spreading props with {...props} and listing them individually. But when should you use each? Here's the guiding principle:

Use spread for HTML passthroughs and library wrappers. When your component is a thin wrapper around a native HTML element (like <button>, <input>, <div>) or a third-party library component, spreading makes sense. You're essentially saying "pass everything down to the underlying element," which is exactly what you want.

function FancyButton({ children, className, ...rest }) {
  return (
    <button className={`fancy ${className}`} {...rest}>
      {children}
    </button>
  );
}

// Works with ANY button prop: onClick, disabled, type, aria-*, etc.

Use explicit props at component boundaries. When creating your own component that isn't wrapping a single native element, define exactly what props it accepts. This creates a clear contract and makes your component's API obvious.

function UserCard({ name, email, avatarUrl, onEdit }) {
  // Clear interface—you know exactly what this component needs
  return (
    <div>
      <img src={avatarUrl} alt={name} />
      <h3>{name}</h3>
      <p>{email}</p>
      <button onClick={onEdit}>Edit</button>
    </div>
  );
}

The Reasoning

Think of spread as a "pass-through tunnel" and explicit props as a "gated entrance." Use the tunnel when you're just forwarding things unchanged. Use the gate when you're building something new that has its own defined interface.

Key Takeaway: Spread props for HTML element wrappers and library passthroughs; use explicit props to define clear component boundaries and APIs.