use-scroll-direction
use-scroll-direction
현재 페이지의 스크롤 방향(위/아래)을 감지하는 훅이에요.
출처: 문서
본문
사용법 (Usage)
페이지를 스크롤하면 스크롤 방향을 'up', 'down', 또는 아직 감지되지 않았을 때 'unknown'으로 반환해요.
import { Badge, Text } from '@mantine/core';
import { useScrollDirection } from '@mantine/hooks';
function Demo() {
const direction = useScrollDirection();
return (
<>
{direction === 'up' && '↑ Scrolling UP'}
{direction === 'down' && '↓ Scrolling DOWN'}
{direction === 'unknown' && 'Scroll to detect direction'}
Scroll the page to see the scroll direction
);
}
정의 (Definition)
function useScrollDirection(): 'up' | 'down' | 'unknown';