Learn and build with the LEGO blocks philosophy for React components
- π― True composition pattern - Based on Fernando Rojo's talk
- π§© Granular LEGO blocks - 13 Settings components, 8 Composer components
- π Interactive learning - Live examples + before/after comparisons
- β‘ React 19 + Compiler - Auto-optimization, no manual memoization
- π¨ Modern stack - Next.js 15, TypeScript, Tailwind, shadcn/ui
- β Production-ready - Tested, accessible, performant
# Clone
git clone https://github.com/francostan/composition-pattern-starter.git
cd composition-pattern-starter
# Install
npm install
# Run
npm run dev- Theory β Read docs/Pattern.md
- Practice β Try /examples
- Compare β See /comparison
- Build β Use as LEGO blocks!
Message composer with attachments, character count, keyboard shortcuts
Provider,Frame,Header,Input,Footer,AttachButton,Attachments,SendButton
Flexible form/dialog system
Provider,Dialog,Trigger,Content,Header,Body,Section,TextField,Toggle,Footer,ResetButton,SaveButton,useSettings
/- Homepage with overview/examples- 3 configurations showing flexibility/comparison- Before/after + LEGO philosophy tabs
- Framework: Next.js 15 (App Router, Turbopack)
- React: 19.1.0 with React Compiler
- Language: TypeScript (strict mode)
- Styling: Tailwind CSS v4 + shadcn/ui
- Linting: Biome (replaces ESLint + Prettier)
- State: Context API + nuqs
βββ app/
β βββ page.tsx # Homepage
β βββ examples/page.tsx # Live examples
β βββ comparison/page.tsx # Comparisons
β βββ layout.tsx # Root layout
βββ components/
β βββ composer/ # 8 files (1 per block)
β βββ settings-dialog/ # 13 files (1 per block)
β βββ ui/ # shadcn/ui components
βββ docs/
β βββ Pattern.md # Composition guide
β βββ Rules.md # UX guidelines
βββ lib/
βββ utils.ts # Helpers
// 1. Organize context: state/actions/meta
const value = {
state: { /* data */ },
actions: { /* functions */ },
meta: { /* refs, config */ }
}
// 2. Export with dot notation
export const Component = {
Provider,
SubComponent,
}
// 3. Compose freely
<Component.Provider>
<Component.SubComponent />
</Component.Provider>See docs/Pattern.md for complete guide.
<Settings.Provider initialState={{ username: "john" }}>
<Settings.Dialog>
<Settings.Trigger><Button>Open</Button></Settings.Trigger>
<Settings.Content>
<Settings.Header title="Settings" />
<Settings.Body>
<Settings.TextField name="username" label="Username" />
<Settings.Toggle name="darkMode" label="Dark mode" />
</Settings.Body>
<Settings.Footer>
<Settings.ResetButton />
<Settings.SaveButton />
</Settings.Footer>
</Settings.Content>
</Settings.Dialog>
</Settings.Provider><Settings.Provider initialState={{ alerts: true }}>
<Settings.Body>
<Settings.Toggle name="alerts" label="Email alerts" />
<Settings.Toggle name="push" label="Push notifications" />
</Settings.Body>
<Settings.SaveButton />
</Settings.Provider>See /examples for more configurations.
Contributions welcome! Here's how:
- Fork the repo
- Create branch:
git checkout -b feature/my-feature - Make changes
- Lint:
npm run lint - Build:
npm run build - Commit:
git commit -m "Add my feature" - Push and create PR
- β Follow existing patterns (state/actions/meta)
- β Use TypeScript
- β Keep components small and focused
- β Add examples for new patterns
- β Run lint before committing
- β One feature per PR
- Export with dot notation
- Organize as state/actions/meta
- No prop drilling
- Use React Compiler (no manual memoization)
Open an issue or reach out to @francostan
npm run dev # Development server
npm run build # Production build
npm run start # Production server
npm run lint # Run Biome linter
npm run format # Format code with Biome# Install Vercel CLI
npm i -g vercel
# Deploy
vercel
# Production
vercel --prodOr connect your GitHub repo to Vercel for automatic deployments.
None required for basic setup!
MIT Β© francostan
See LICENSE for details.
- Pattern: Fernando Rojo's composition talk
- UI: shadcn/ui
- Inspiration: React community
This template serves three purposes:
- π Educational - Learn composition patterns through examples
- π οΈ Practical - Copy production-ready components
- π€ Community - Open for contributions
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Author: @francostan
Made with β€οΈ by francostan