- Props: Ideal for customizing simple, static content such as text, images URLs, numbers, or other basic data types.
- Slots: Provide greater flexibility by allowing you to insert arbitrary React nodes directly into components. Slots utilize the React composition pattern, offering more control and interactivity while avoiding prop drilling.
Recommended usage
- Use props for straightforward, static content updates like titles, labels, image URLs, and simple data.
- Use slots when you require dynamic content or need access to specific subcomponent properties like event handlers (
onClick
,onChange
) or attributes (alt
,src
).
<TrackCard />
component from the previous example.
Subcomponents can help clarify intended usage by explicitly exposing slots and relevant props to the consumer of a
component. The
<TrackCardWithSlots.FavoriteButton />
subcomponent is a good example of this in the example above.