Skip to content

Commit

Permalink
Merge pull request #80 from avelican/main
Browse files Browse the repository at this point in the history
fix scrolling on iOS and desktop
  • Loading branch information
Supernova3339 authored Feb 5, 2024
2 parents c2ddf29 + 72fb78a commit 74cb1ac
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 74cb1ac

Please sign in to comment.