React Context, Custom Hooks, and the Rendering Traps Between Them
Context subscriptions bypass React.memo, so a component that both subscribes to Context and receives frequent parent re-renders will still re-render on every value change regardless of memoization. Misunderstanding this interaction leads to performance regressions that profiling tools attribute to the wrong cause.
Component communication in React splits into four clear patterns: parent-child props, sibling state lifting, grandparent-grandchild Context tunnels, and stranger state libraries. The pain that useContext solves is real—intermediate components forced to forward props they never use—and the three-step template of createContext, Provider, and useContext replaces that with a direct subscription model that still respects unidirectional data flow.
Encapsulating Context consumption into a custom Hook like useTheme adds validation that catches missing Providers immediately, rather than letting components silently fall back to default values. The same encapsulation pattern extends to browser APIs: a useMouse Hook abstracts mousemove listeners into reusable state, but the high event frequency forces a hard choice between useState for UI-bound coordinates and useRef for computation-only tracking that avoids rendering entirely.
React.memo can block parent-chain re-renders but cannot stop a Context subscription from forcing an update—a design guarantee that subscribed components always stay in sync. The useEffect cleanup pattern, returning a function that removes event listeners, prevents the memory leaks that accumulate when components mount and unmount repeatedly without releasing native resources.
The tutorial's framing of Context as an 'elevator' versus props as 'stairs' is pedagogically effective but obscures a real cost: every Context consumer re-renders on value change, which makes Context unsuitable for high-frequency state even when the mental model suggests it fits.
Validating Context presence inside a custom Hook is a small change with outsized debugging leverage—silent fallback to default values is one of the most common and hardest-to-spot Context bugs in production.
The useState-versus-useRef decision for mouse coordinates is a microcosm of a broader React performance pattern: rendering is cheap until it isn't, and the threshold depends entirely on downstream component tree complexity.