chatpad/src/components/ScrollIntoView.tsx
2023-08-16 17:13:05 +02:00

16 lines
358 B
TypeScript

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={myRef}>
{children}
</div>
);
}