React Cheat Sheet

Comprehensive React reference covering JSX, hooks, component patterns, Context API, React Router, and TypeScript integration with practical code examples.

React Best Practices

πŸͺ Prefer Function Components

Use function components with hooks β€” they are simpler, more composable, and the future of React

πŸ”‘ Stable Keys in Lists

Always use unique, stable IDs as keys β€” avoid array indices unless the list is static and never reordered

🧹 Clean Up Effects

Return a cleanup function from useEffect for subscriptions, timers, and async operations to prevent memory leaks

πŸ“¦ Collocate State

Keep state as close as possible to where it is used β€” lift state only when genuinely needed by siblings

🧩 Small, Focused Components

Extract components when a chunk of JSX becomes complex or reusable β€” aim for single responsibility

⚑ Optimize Last

Profile with React DevTools before adding memo/useMemo/useCallback β€” premature optimization adds complexity without measurable gains