import React, { useEffect, useRef } from 'react';
import Message from './Message';
import Landing from './Landing';
export default function Messages({ messages }) {
if (messages.length === 0) {
return ;
}
const messagesEndRef = useRef(null);
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};
// this useEffect triggers the following warning:
// Warning: Internal React error: Expected static flag was missing.
useEffect(() => {
scrollToBottom();
}, [messages]);
return (
{messages.map((message, i) => (
))}
);
}