---
name: frontend-component-patterns
description: Build reusable, composable, and maintainable React/Vue/Angular components following established design patterns like compound components, render props, custom hooks, and HOCs. Use when creating component libraries, implementing component composition, building reusable UI elements, designing prop APIs, managing component state patterns, implementing controlled vs uncontrolled components, creating compound components, using render props or children as functions, building custom hooks, or establishing component architecture standards.
---
# Frontend Component Patterns - Building Reusable React Components
## When to use this skill
- Creating reusable component libraries
- Implementing component composition patterns
- Building flexible, configurable UI components
- Designing intuitive component prop APIs
- Managing component state with patterns
- Implementing controlled vs uncontrolled components
- Creating compound components (e.g., Tabs, Accordion)
- Using render props or children as functions
- Building custom React hooks for shared logic
- Implementing Higher-Order Components (HOCs)
- Establishing component architecture standards
- Creating accessible, keyboard-navigable components
## When to use this skill
- Designing React component architecture, improving component reusability, managing state, or solving common UI patterns.
- When working on related tasks or features
- During development that requires this expertise
**Use when**: Designing React component architecture, improving component reusability, managing state, or solving common UI patterns.
## Core Principles
1. **Composition Over Inheritance** - Build complex UIs from simple components
2. **Single Responsibility** - Each component does one thing well
3. **Props Down, Events Up** - Unidirectional data flow
4. **Separation of Concerns** - Logic separate from presentation
5. **Accessibility First** - ARIA, keyboard navigation, semantic HTML
## Component Patterns
### 1. **Presentational vs Container Components**
```typescript
// ❌ Mixed concerns - logic + presentation together
function UserProfile() {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch(`/api/users/${userId}`)
.then(r => r.json())
.then(setUser)
.finally(() => setLoading(false));
}, [userId]);
if (loading) return
);
}
```
## Component Design Checklist
```
Structure:
□ Single responsibility per component
□ Presentational vs container separation
□ Proper props typing (TypeScript)
□ Default props defined
□ Prop validation for critical inputs
State Management:
□ State at lowest necessary level
□ Lifted state when needed for sharing
□ Context for deep prop drilling
□ No prop mutations
□ Controlled components for forms
Performance:
□ memo() for expensive components
□ useMemo() for expensive calculations
□ useCallback() for stable callbacks
□ Code splitting for large components
□ Lazy loading for routes
Accessibility:
□ Semantic HTML elements
□ ARIA labels and roles
□ Keyboard navigation support
□ Focus management
□ Screen reader tested
Reusability:
□ Configurable via props
□ Composable with children
□ No hardcoded values
□ Clear, documented API
□ Example usage provided
```
## Resources
- [React Documentation](https://react.dev/)
- [React Patterns](https://reactpatterns.com/)
- [Compound Components](https://kentcdodds.com/blog/compound-components-with-react-hooks)
- [WAI-ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/)
---
**Remember**: Great components are simple, reusable, accessible, and performant. Start simple, add complexity only when needed.