Skip to content

Commit

Permalink
fix scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
avelican committed Aug 16, 2023
1 parent e8240a7 commit 72fb78a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/ScrollIntoView.tsx
Original file line number Diff line number Diff line change
@@ -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>
);
Expand Down

0 comments on commit 72fb78a

Please sign in to comment.