React¶
Scope: web front ends built with React, either on their own or inside a framework. Framework-independent rules for accessibility, Core Web Vitals (WEB-4) and browser security are in Web front end.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 10 react.dev: Learn React: the baseline. The official tutorial covers component design and state management.
- 9 Rules of React: rules that React code must follow to behave correctly.
- 9 Thinking in React: the official method for breaking a UI into components and state.
- 7 Bulletproof React: an opinionated, production-ready project architecture.
- 6 Patterns.dev: design, rendering and performance patterns.
Key rules¶
- 9
REACT-1Keep components and hooks pure. Side effects belong in event handlers or Effects. (react.dev, Keeping components pure, Rules of React) - 7
REACT-2Keep state minimal. Don't store what you can derive during render, and avoid duplicated or contradictory state. (react.dev, Choosing the state structure) - 7
REACT-3Don't use Effects to transform data or handle user events. (react.dev, You might not need an Effect) - 7
REACT-4Put state where it's used, and lift it only as far as the closest common parent. (react.dev, Sharing state between components, Dodds, Colocation) - 7
REACT-5Treat server state (fetched and cached data) separately from UI state, for example with TanStack Query. (TanStack Query overview, Dodds, Application state management with React) - 7
REACT-6Test components with React Testing Library, which renders them into the DOM and queries them the way users find things. The principle, querying by role and label rather than implementation details, isWEB-14in Web front end. (Testing Library, Guiding principles) - 6
REACT-7Start new apps with a framework, or with a build tool such as Vite when you have specific constraints. (react.dev, Creating a React App) - 6
REACT-8Try props and composition before reaching for context. (react.dev, Passing data deeply with context) - 6
REACT-9Extract reusable stateful logic into custom hooks. (react.dev, Reusing logic with custom hooks) - 6
REACT-10Organise larger apps by feature, not by file type. (Bulletproof React, project structure, Feature-Sliced Design) - 6
REACT-11Move non-view logic (domain, data access) out of components as the app grows. (Modularizing React Applications with Established UI Patterns)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 8 eslint-plugin-react-hooks: the official lint rules, including the React Compiler checks.
purityflags impure components and hooks, andset-state-in-effectflags data transformed or state derived in Effects. ChecksREACT-1andREACT-3, and partlyREACT-2. - 5 eslint-plugin-testing-library: flags tests that reach into DOM nodes or containers instead of using user-facing queries. Checks
REACT-6. - 5 eslint-plugin-boundaries: enforces which folders may import which, for example no imports across features, or from components into data access. Checks
REACT-10, and partlyREACT-11.
Tutorials and further reading¶
- 6 Micro Frontends (Cam Jackson): when splitting a front end across teams is worth the cost.
- 6 Server Components (react.dev).