fix scrolling

This commit is contained in:
avelican 2023-08-16 17:13:05 +02:00
parent e8240a7bef
commit 72fb78aef7

View file

@ -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 (
<div
ref={(node) => {
if (!node) return;
node.scrollIntoView({ behavior: "smooth" });
}}
>
<div ref={myRef}>
{children}
</div>
);