Skip to main content
Albero Academy

Patterns & Best Practices

Tie it together — component composition, project structure, the habits of maintainable React, and the mistakes to avoid.

Chapter 16React15 min readBeginner friendly
  • #React
  • #Best Practices
  • #Patterns

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 giant components/.
  • 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

derive during render
// ✗ redundant state that can drift out of sync
const [items, setItems] = useState([]);
const [count, setCount] = useState(0); // don't — derive it
// ✓ just compute it
const count = items.length;
const activeItems = items.filter(i => i.active);

Common mistakes

MistakeFix
Array index as keyUse a stable unique id
Mutating stateCopy with spread, then set
Missing effect dependenciesInclude everything the effect uses
Too much in one componentSplit into smaller ones
Redundant/duplicated stateDerive it during render
Overusing Context/memoReach 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

  1. 01Favour composition (children/slots) and small single-purpose components over prop-heavy configuration.
  2. 02Structure by feature and co-locate related files; extract hooks and shared UI.
  3. 03Derive values during render instead of duplicating them in state (less state = fewer bugs).
  4. 04Avoid the classics: index keys, state mutation, missing effect deps, giant components.
  5. 05Reach for Context/memoisation deliberately — clear, honest data flow beats clever abstractions.