Notes
02Performance / Interface

The cursor never enters React state

3 min read

The obvious implementation of a custom cursor is a piece of state holding x and y, updated on pointermove. It works immediately, which is the problem — the cost does not show up until the page has enough on it to notice, and by then the cursor is wired into a dozen components.

Every pointermove sets state. Every set re-renders the provider. Every re-render reconciles its subtree. You are running React sixty times a second to change two numbers on a single transform, and the work scales with how much of the page is inside the provider, which is all of it.

Coordinates are not state

Pointer position is not application state. Nothing renders differently because of it — one element moves. So it should never enter the render path at all. The cursor engine here writes transforms directly, and the context exposes only a stable API: set a variant, reset, switch tone. Those change on hover, not on move, so they are rare enough to be state.

ts
// quickTo keeps a single interpolating tween alive per property,
// so this is a property write, not a new tween per event.
const xTo = gsap.quickTo(el, 'x', { duration: 0.4, ease: 'power3' })
const yTo = gsap.quickTo(el, 'y', { duration: 0.4, ease: 'power3' })

window.addEventListener('pointermove', (e) => {
  xTo(e.clientX)
  yTo(e.clientY)
}, { passive: true })

The result is that hovering costs zero renders. The same rule covers pointer parallax, magnetic buttons and scroll progress: if a value changes at input rate and only one element reads it, it belongs in a ref and a transform, not in state.