v6.0.35

use-window-scroll

Subscribe to window scroll and scroll smoothly to given position
Import

Usage

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

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

Definition

function useWindowScroll(): readonly [
{ x: number; y: number },
(position: { x?: number; y?: number }) => void
];