From 72fb78aef79e75fabd2c5299585bb0830555a396 Mon Sep 17 00:00:00 2001 From: avelican Date: Wed, 16 Aug 2023 17:13:05 +0200 Subject: [PATCH] fix scrolling --- src/components/ScrollIntoView.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/ScrollIntoView.tsx b/src/components/ScrollIntoView.tsx index 39a5718..eaf3a47 100644 --- a/src/components/ScrollIntoView.tsx +++ b/src/components/ScrollIntoView.tsx @@ -1,13 +1,15 @@ -import { ReactNode } from "react"; +import { ReactNode, useRef, useEffect } from "react"; export function ScrollIntoView({ children }: { children: ReactNode }) { + + // Scroll into view as soon as we appear + const myRef = useRef(null); + useEffect(() => { + myRef.current.scrollIntoView({ behavior: 'smooth' }); + }, []); + return ( -
{ - if (!node) return; - node.scrollIntoView({ behavior: "smooth" }); - }} - > +
{children}
);