Subscribe to window scroll and scroll smoothly to given position


Hook returns current scroll position and a function to scroll smoothly to given position:

Scroll position x: 0, y: 0
import { useWindowScroll } from '@mantine/hooks';
import { Button, Text, Group } from '@mantine/core';
function Demo() {
const [scroll, scrollTo] = useWindowScroll();
return (
<Group position="center">
Scroll position x: {scroll.x}, y: {scroll.y}
<Button onClick={() => scrollTo({ y: 0 })}>Scroll to top</Button>


function useWindowScroll(): readonly [
{ x: number; y: number },
(position: { x?: number; y?: number }) => void
Build fully functional accessible web applications faster than ever
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback