Named slots

A component can offer more than one place to fill in content. Besides children, any prop can hold JSX, so a card can have named slots for its header, footer and media.

A slot is an ordinary prop: leave it out to skip it, or give it a default value as a fallback. Unlike render props, a slot receives finished markup instead of a function.

function Card({ accent, media, header, footer = <small>No footer</small>, children }) {
  return (
    <article class="sl-card" style={`--accent: ${accent}`}>
      {media && <figure>{media}</figure>}
      {header && <header>{header}</header>}
      <div class="sl-content">{children}</div>
      <footer>{footer}</footer>
    </article>
  );
}

// No footer given, so the default renders.
<Card
  accent="#a855f7"
  media={<span class="sl-avatar">AL</span>}
  header={
    <>
      <h3>Ada Lovelace</h3>
      <span class="sl-kicker">Analytical engineer</span>
    </>
  }
>
  <dl class="sl-stats">…</dl>
</Card>

One component, three cards

AL

Ada Lovelace

Analytical engineer
Commits
1,843
Reviews
412
Streak
37 d
No footer
⚡
New

Instant previews

Slots can hold anything: text, lists, buttons or other components.

If a slot needs data from the component, pass a function instead: see Render props.