Skip to content

Rule · Smoothness

React re-renders while the page scrolls

smooth/react-commits-on-scrollwarnvoid smoothupdated

Why it matters

Scroll position, scroll-spy or in-view state held in React turns every scroll event into a render and commit on the main thread, the same thread that must produce each scroll frame. It costs little on a fast laptop and drops frames on a phone.

How to fix it

Keep scroll position out of React state: drive the effect with CSS scroll-driven animations or IntersectionObserver, write to a ref and update the DOM in requestAnimationFrame, or subscribe with useSyncExternalStore and only emit when a threshold is crossed.

Example

ts
// before: const [y, setY] = useState(0); onScroll = () => setY(scrollY)
// after: only re-render when the header state actually flips
const scrolled = useSyncExternalStore(subscribeScroll, () => scrollY > 80);

References

void smooth reports 18 rules in this category. How the page feels after it loads: dropped frames during a scripted scroll, long animation frames, INP of real clicks, shifts after input, animated layout properties, idle rAF loops and reduced-motion handling.