import React, { useEffect, useState, useRef } from 'react'; import useDidMountEffect from '~/hooks/useDidMountEffect'; import Message from './Message'; import ScrollToBottom from './ScrollToBottom'; const Messages = ({ messages }) => { const [showScrollButton, setShowScrollButton] = useState(false); const scrollableRef = useRef(null); const messagesEndRef = useRef(null); useEffect(() => { const scrollable = scrollableRef.current; const hasScrollbar = scrollable.scrollHeight > scrollable.clientHeight; setShowScrollButton(hasScrollbar); }, [scrollableRef]); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; const handleScroll = (e) => { const bottom = e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight; if (bottom) { setShowScrollButton(false); } else { setShowScrollButton(true); } }; const scrollHandler = (e) => { e.preventDefault(); scrollToBottom(); }; return (