Compound components offer flexibility in component composition but aren't always the right choice. They work best for static content with dynamic layouts (like RadioGroups or ButtonGroups), not for fixed layouts or dynamic content (like Selects). For type safety, use a component factory pattern: export a function like `createRadioGroup<T>()` that returns typed components, tying type parameters together without requiring manual annotations on each child component. This preserves flexibility while ensuring strong type guarantees across parent and child components.

8m read timeFrom tkdodo.eu
Post cover image
Table of contents
A Bad ExampleSlotsA Better ExampleType Safety

Sort: