react-hooks-patterns
React Hooks Patterns
Master modern React hooks patterns for building scalable, maintainable applications with proper state management, side effects, and custom logic reuse.
Common Hooks
useState
const [count, setCount] = useState(0);
const [user, setUser] = useState<User | null>(null);
// Functional updates
setCount(prev => prev + 1);
useEffect
useEffect(() => {
// Side effect
const subscription = api.subscribe();
return () => subscription.unsubscribe();
}, [dependencies]);
useContext
const theme = useContext(ThemeContext);
useMemo & useCallback
const memoized = useMemo(() => expensive(a, b), [a, b]);
const callback = useCallback(() => doSomething(a), [a]);
Custom Hooks
function useFetch<T>(url: string) {
const [data, setData] = useState<T | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
fetch(url)
.then(res => res.json())
.then(setData)
.catch(setError)
.finally(() => setLoading(false));
}, [url]);
return { data, loading, error };
}
Best Practices
- Always provide dependency arrays
- Use useCallback for event handlers
- Create custom hooks for reusable logic
- Keep components focused and small
- Use TypeScript for type safety
- Clean up effects properly
- Avoid excessive use of useEffect
Resources
More from spjoshis/claude-code-plugins
excel-analysis
Master Excel for data analysis with pivot tables, formulas, Power Query, and advanced Excel techniques.
50bloc-pattern
Master BLoC (Business Logic Component) pattern for Flutter with flutter_bloc. Learn events, states, testing, and advanced patterns for scalable apps.
9security-assessment
Master security assessments with vulnerability scanning, penetration testing, security testing, and security audits.
5product-roadmapping
Master product roadmapping with strategic planning, OKRs, feature prioritization, timeline management, and stakeholder alignment for successful product delivery.
5performance-testing
Master performance testing with load testing, stress testing, JMeter, k6, and performance benchmarking.
5scalability-patterns
Master scalability patterns with load balancing, caching, database scaling, microservices, and horizontal scaling strategies.
5