Skip to main content

The Pattern

Instead of importing multiple components:
You import one component with slots:
Cleaner imports. Clear relationships. Better discoverability.

Creating Slots

Use withSlots() to attach child components to a parent.
Now Card.Header, Card.Body, and Card.Footer are available.

Slots + Context

Slots become powerful when combined with context. Children automatically inherit parent variants.
Usage:
All slots automatically get intent="success" styling.
When slot components share the same variants and context, use styledConfig() to avoid duplicating the config.

Nested Slots

You can add slots to components that already have slots.

displayName

Slots preserve the original component’s display name for React DevTools.

When to Use Slots

Use slots when:
  • Components are meant to be used together
  • You want dot notation for better DX
  • Parent-child relationships should be obvious
Don’t use slots when:
  • Components are independent
  • There’s no clear parent-child relationship
  • You’re just grouping unrelated components

Slots vs Children

Slots don’t restrict what children you can use. They’re just a convenient way to access related components.

Next: React Native Guide

Using better-styled with React Native