componentEngineering
Components, the hooks rules, the render model, and the traps that cause most React bugs.
1 item
The mental model
A component is a function of its props and state that returns UI. React re-renders when state or props change, diffs the result against the previous render, and applies the minimal DOM changes. "Re-render" means React calls your function again — it does not mean the DOM was touched. Most performance confusion comes from conflating the two.
Hooks — the rules that actually matter
useState — local state; setter triggers a re-render. Updates are batched, and state is a snapshot per render (count inside a closure is the value at render time, not "live").useEffect — for synchronizing with external systems (subscriptions, DOM, network), not for deriving data. If you can compute it during render, don't put it in an effect.exhaustive-deps lint rule guide you.useRef — a mutable box that survives renders without triggering one. For DOM nodes and "I need to remember something but not re-render."Common traps
useState and sync with an effect.key in lists, or using array index as key when the list reorders — causes subtle state-bleed bugs. Use a stable unique id.useMemo/useCallback only when it matters.Composition over configuration
children and small focused components over giant prop-driven mega-components.