Overview of React Composition Patterns
mainThe composition-patterns skill provides a structured set of React patterns designed to help developers build scalable component architectures. The primary goal is to avoid 'boolean prop proliferation' (adding many boolean props to a single component to handle different behaviors) by utilizing techniques like compound components, lifting state, and composing internals.
Core Principles
- Composition over configuration: Instead of adding more props to a component to handle every edge case, allow consumers to compose the component using subcomponents.
- Lift your state: Move state into provider components rather than trapping it inside individual UI components.
- Compose your internals: Design subcomponents so they can access shared context directly instead of relying on prop drilling.
- Explicit variants: Avoid generic components with boolean flags (e.g.,
isThread). Instead, create specific, named components likeThreadComposerorEditComposer.