mirror of
https://github.com/deiucanta/chatpad.git
synced 2026-03-11 09:04:31 +00:00
fix scrolling
This commit is contained in:
parent
e8240a7bef
commit
72fb78aef7
1 changed files with 9 additions and 7 deletions
|
|
@ -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>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue