Files
yaak/src-web/hooks/useScrollIntoView.ts
2024-08-15 09:09:18 -07:00

10 lines
249 B
TypeScript

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