Skip to content

Commit

Permalink
Automatically scroll to the latest log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester committed Oct 29, 2024
1 parent 46b0c6b commit 4caa443
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import * as React from "react";
import Box from "@mui/material/Box";
import { useEffect, useRef } from "react";

interface BoxProps {
children?: React.ReactNode;
}

const BoxBasic = (props: BoxProps) => {
const messagesEndRef = useRef<null | HTMLDivElement>(null);

const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
};

useEffect(() => {
scrollToBottom();
}, [props.children]);

return (
<Box
component="section"
Expand Down

0 comments on commit 4caa443

Please sign in to comment.