You're Using React Compound Components Wrong
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
Most React compound component tutorials use a `<Select>/<Option>` example that is actually the wrong use case for the pattern. Compound components are designed for layout flexibility with heterogeneous, mostly-static content (tabs, cards, toolbars), not for rendering data-driven lists. When options come from data, a plain props API is simpler, more type-safe, and easier to sort/filter/virtualize. The post also addresses the TypeScript trap of trying to restrict children via `ReactElement` types — which is leaky and unreliable — and instead advocates putting type safety in shared context, optionally using a generic factory function like `createTabs<T extends string>()` to enforce valid tab values at compile time. A quick decision rule is offered: layout → compound components; data → props; need internal state exposed → render props or hooks.
Table of contents
Your AI shouldn't grade its own homework (Partner)What compound components actually are?The example everyone copies is the wrong oneWhen the pattern actually earns its keepThe type-safety trap: don’t police your childrenWhere the types should come from: contextSo which one do you reach for?📌 TL;DR665.1K Impressions18 Comments