Rules of React
The official rules React code must follow: components and hooks are pure, React calls components and hooks, and the Rules of Hooks apply.
In more detail
They let React render in any order, repeat or skip work safely. The React Compiler depends on them and skips optimising any code that breaks them.
Related terms
- Rules of Hooks — The two rules for hooks: call them only at the top level, never in conditions, loops or nested functions, and only from React components or custom hooks.
- pure function — A function whose result depends only on its arguments and which has no side effects, so the same inputs always give the same output.
- React Compiler — A build-time tool from the React team that automatically adds memoization to components and hooks, so you rarely need useMemo, useCallback or React.memo.
Taught in
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture