loading code fetching the highlighted snippet
useScroll emits a 0→1 motion value tracking a container's scroll position. Pass it through useSpring and drive transform: scaleX(progress) on a bar — it grows as the user scrolls.
useScroll({ container }) returns a scrollYProgress motion value that runs 0 at the top to 1 at the bottom.
Reading $scrollYProgress directly gives you the raw scroll fraction.useSpring turns the linear progress into a smoothed motion
value — the bar lags slightly and overshoots gently. Drop the spring if you want strict
1:1 scroll mapping.container: () => containerEl) so useScroll can resolve the
bound element after mount — at script-run time the binding is still undefined.