drop onreveal

This commit is contained in:
Simon Knott 2024-11-19 14:18:11 +01:00
parent dc064d414f
commit 02436c6aaf
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -133,12 +133,11 @@ export function useAnchor(id: AnchorID, onReveal: () => void) {
}, [id, onReveal]); }, [id, onReveal]);
} }
export function Anchor({ id, onReveal, children }: React.PropsWithChildren<{ id: AnchorID, onReveal?(): void }>) { export function Anchor({ id, children }: React.PropsWithChildren<{ id: AnchorID }>) {
const ref = React.useRef<HTMLDivElement>(null); const ref = React.useRef<HTMLDivElement>(null);
const onAnchorReveal = React.useCallback(() => { const onAnchorReveal = React.useCallback(() => {
onReveal?.();
requestAnimationFrame(() => ref.current?.scrollIntoView({ block: 'start', inline: 'start' })); requestAnimationFrame(() => ref.current?.scrollIntoView({ block: 'start', inline: 'start' }));
}, [onReveal]); }, []);
useAnchor(id, onAnchorReveal); useAnchor(id, onAnchorReveal);
return <div ref={ref}>{children}</div>; return <div ref={ref}>{children}</div>;