blob: fd8919edef34c43b305afec48da1c492c14e7d0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import { useEffect } from 'react';
export const useScrollToReference = <T extends Element = HTMLDivElement>(
ref?: React.RefObject<T | null>,
scroll?: boolean,
onScrolled?: () => void,
) => {
useEffect(() => {
if (scroll) {
ref?.current?.scrollIntoView({ behavior: 'instant', block: 'start' });
onScrolled?.();
}
}, [onScrolled, ref, scroll]);
};
|