import React, { ForwardedRef, useEffect, useRef } from 'react'; interface ConversationProps { messages: string[]; onResendClick: () => void; onEditClick: () => void; onCopyClick: () => void; } const ConversationFrontend = React.forwardRef( ({ messages, onResendClick, onEditClick, onCopyClick }, ref: ForwardedRef) => { const endOfMessagesRef = useRef(null); // Auto-scroll to the bottom of the conversation whenever a new message is added useEffect(() => { if (endOfMessagesRef.current) { endOfMessagesRef.current.scrollIntoView({ behavior: 'smooth' }); } }, [messages]); // Triggers the effect whenever the 'messages' array changes return (
{messages.map((message, index) => { const isUserMessage = message.startsWith('User:'); console.log(messages) return (

{message}

); })} {/* Dummy div to mark the end of the conversation for auto-scrolling */}
); } ); export default ConversationFrontend;