Each pattern exposes a minimal, focused API. Let me walk through the interfaces for the six core patterns.
Compound Components
compound-tabs.tsxtsx
[object Object]
The compound API is my favorite pattern. The parent (Tabs) owns state and provides it via Context. Children (Tab, Panel) consume it implicitly. The consumer arranges them like HTML — declarative, composable, and type-safe.
Render Props
render-props.tsxtsx
[object Object]
Render props invert control: instead of the component deciding how to render data, the consumer passes a function that receives the data and returns JSX. This is ideal for components that manage async state (loading, error, data) but should not dictate the UI.
Higher-Order Components
hoc.tsxtsx
[object Object]
HOCs wrap a component to inject props. I use them sparingly — they hide the prop source and make debugging harder. But for cross-cutting concerns like authentication, they are still the clearest pattern. The key is to keep them thin: an HOC should inject props, not transform behavior.
Custom Hooks
use-debounced-search.tstsx
[object Object]
Custom hooks are the workhorse of modern React. Unlike HOCs and Render Props, hooks compose naturally — you can call multiple hooks in a single component, and they share state implicitly through closure. The useDebouncedSearch hook above encapsulates both debounce timing and fetch lifecycle in about 30 lines.
Provider Pattern
theme-provider.tsxtsx
[object Object]
The Provider pattern is Context with guardrails. The useTheme hook throws a descriptive error if called outside a provider — no silent undefined crashes. The context value is memoized so that consumers only re-render when the actual value changes.
Publisher-Subscriber
event-bus.tstypescript
[object Object]
The EventBus uses a generic EventMap type parameter for full type safety. The on() method returns an unsubscribe function — no separate off() method needed. I use queueMicrotask to dispatch events asynchronously, preventing the emitter from blocking on listener execution.
Container/Presenter
container-presenter.tsxtsx
[object Object]
Factory & Singleton
button-factory.tsxtsx
[object Object]
analytics-tracker.tstypescript
[object Object]