Files
yaak/src-web/hooks/useScrollIntoView.ts
2024-08-15 05:50:38 -07:00

10 lines
266 B
TypeScript

import { useEffect } from 'react';
export function useScrollIntoView<T extends HTMLElement>(node: T | null, active: boolean) {
useEffect(() => {
if (active) {
node?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}, [active, node]);
}