Commit 4ff58000 authored by Kantz's avatar Kantz
Browse files

autoscrolling

parent ee2773fc
import { useEffect, useRef } from "react";
import MessageBubble from "./MessageBubble"; import MessageBubble from "./MessageBubble";
export type ChatMessage = { export type ChatMessage = {
...@@ -11,8 +12,16 @@ type MessageListProps = { ...@@ -11,8 +12,16 @@ type MessageListProps = {
}; };
export default function MessageList({ messages }: MessageListProps) { export default function MessageList({ messages }: MessageListProps) {
const listRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
if (listRef.current) {
listRef.current.scrollTop = listRef.current.scrollHeight;
}
}, [messages.length]);
return ( return (
<div className="message-list"> <div className="message-list" ref={listRef}>
{messages.map((message) => ( {messages.map((message) => (
<MessageBubble <MessageBubble
key={message.id} key={message.id}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment