You now know the whole toolkit. This closing chapter is about judgement — the patterns and habits that keep a React codebase maintainable as it grows, and the classic mistakes that cause the bugs and rewrites. Good React is mostly small, honest components and clear data flow.
Composition over configuration
Build flexible components by composing them (via children and slots), not by adding a prop for every variation. A Card that takes children beats one with fifteen boolean props. Keep components small and single-purpose.
Project structure
- Group by feature, not by type — a
students/folder with its components, hooks and API, rather than one giantcomponents/. - Co-locate: keep a component's styles, tests and helpers next to it.
- Extract reusable logic into custom hooks and shared UI into a
ui/folder.
Derive, don't sync
// ✗ redundant state that can drift out of syncconst [items, setItems] = useState([]);const [count, setCount] = useState(0); // don't — derive it// ✓ just compute itconst count = items.length;const activeItems = items.filter(i => i.active);
Common mistakes
| Mistake | Fix |
|---|---|
| Array index as key | Use a stable unique id |
| Mutating state | Copy with spread, then set |
| Missing effect dependencies | Include everything the effect uses |
| Too much in one component | Split into smaller ones |
| Redundant/duplicated state | Derive it during render |
| Overusing Context/memo | Reach for them only when needed |
Practice
Refactor a bloated component: split it into smaller ones, replace a piece of redundant state with a derived value, extract a custom hook, and fix any array-index keys or state mutations. You've now completed React end to end.
Key takeaways
- 01Favour composition (children/slots) and small single-purpose components over prop-heavy configuration.
- 02Structure by feature and co-locate related files; extract hooks and shared UI.
- 03Derive values during render instead of duplicating them in state (less state = fewer bugs).
- 04Avoid the classics: index keys, state mutation, missing effect deps, giant components.
- 05Reach for Context/memoisation deliberately — clear, honest data flow beats clever abstractions.
