Back to Mantine

Use Window Scroll

apps/mantine.dev/src/pages/hooks/use-window-scroll.mdx

9.2.2922 B
Original Source

import { UseWindowScrollDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';

export default Layout(MDX_DATA.useWindowScroll);

Usage

The use-window-scroll hook returns the current scroll position and a function to scroll smoothly to a given position:

<Demo data={UseWindowScrollDemos.usage} />

Definition

tsx
interface UseWindowScrollPosition {
  x: number;
  y: number;
}

type UseWindowScrollTo = (position: Partial<UseWindowScrollPosition>) => void;
type UseWindowScrollReturnValue = [UseWindowScrollPosition, UseWindowScrollTo];

function useWindowScroll(): UseWindowScrollReturnValue;

Exported types

The UseWindowScrollTo, UseWindowScrollPosition, and UseWindowScrollReturnValue types are exported from @mantine/hooks;

tsx
import type { UseWindowScrollTo, UseWindowScrollPosition, UseWindowScrollReturnValue } from '@mantine/hooks';