React
Hooks, composition patterns, component implementations, and the measurements behind the performance decisions.
content/react12 notes
Everything here has been through a real codebase. The hooks are the ones I kept reaching for, the patterns are the ones that survived review, and the performance notes exist because I measured something and did not want to measure it again.
How this is organised
Each directory holds one kind of answer:
- hooks, small single-purpose hooks with the edge cases written down.
- patterns, ways of composing components, and when each one costs more than it saves.
- components, complete implementations, accessibility included.
- performance, decisions backed by numbers rather than instinct.
- state-management, keeping state without reaching for a library.
- testing, what is worth asserting, and what only looks like a test.
Every note is a directory of plain files, so the code beside a note is the code the note is about.
Everything in this category
hooks/
- useEventListener hookAttach a DOM event listener once and keep the handler current, so a changing callback never detaches the listener.
- useMediaQuery hookSubscribe to a CSS media query from React, without a resize listener or a layout read.
- useLocalStorage hookA state hook that mirrors its value into localStorage, with safe hydration and cross-tab synchronization.
- useIntersectionObserver hookTrack element visibility for lazy loading, infinite scroll and scroll-spy navigation.
performance/
patterns/
- Compound componentsExpose a component's internals as named subcomponents that share state through a private context.
- Render propsHand rendering control to the caller through a function child, and when a hook is the better answer.
- Error boundariesKeep a render-time failure inside one subtree, and recover from it without a full page reload.