I'll enhance your code to include a message history display that grows naturally and only becomes scrollable after reaching a maximum height. Here's the complete updated code:
Added sentMessages state to track all sent messages
Updated sendTextMessage to add messages to history
Dynamic Message Display:
Created a scrollable message history area that:
Grows naturally with content
Stops growing at max-h-[300px]
Then becomes scrollable with overflow-y-auto
Added proper styling for each message bubble
Auto-Scrolling:
Added messagesEndRef to automatically scroll to the bottom when new messages arrive
Implemented useEffect to handle the scrolling behavior
Improved Layout:
Better organized the message section with proper spacing
Made the message history take up available space with flex-1
Added visual separation between message history and input area
Visual Enhancements:
Added proper styling for message bubbles
Improved the empty state display
Maintained consistent styling with the rest of the UI
This implementation provides a much better user experience for viewing message history while maintaining all the existing functionality. The message area will now grow naturally with content and only become scrollable when it reaches the maximum height.