When Prop Getters Beat Component Slots
You'll learn when to choose prop getters over component slots for better developer experience.
The Comparison
Both prop getters and component slots (passing JSX as props) solve similar problems: they let users customize parts of your component. But they shine in different scenarios.
Component slots work great when users need to:
- Replace large chunks of UI
- Provide static content
- Customize appearance without touching behavior
Prop getters win when users need to:
- Add behavior to existing elements in their own code
- Merge your component's logic with their own handlers
- Apply standard patterns to multiple elements
- Keep full control over the DOM structure
The Key Difference
Slots say: "I'll render whatever you give me in this spot."
Prop getters say: "Take these props and apply them to your element wherever you want."
When Prop Getters Are Better
Imagine a combobox library. With slots, you'd have to provide components:
<Combobox>
<Combobox.Input placeholder="Search..." />
<Combobox.List>...</Combobox.List>
</Combobox>
The library controls the DOM structure. With prop getters, users keep control:
const { getInputProps, getListProps } = useCombobox(...)
return (
<div className="my-custom-wrapper">
<input {...getInputProps()} className="my-input" />
<ul {...getListProps()}>...</ul>
</div>
)
Prop getters shine when users need behavioral composition (merging your logic with theirs) over structural composition (arranging pre-built pieces).
Key Takeaway: Choose prop getters when users need to integrate your component's behavior into their own DOM structure; choose slots when you control the structure and users just fill in content.