Rev 15852 | Rev 16001 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useRef, useEffect } from "react";
import Message from "./Messages";
import styles from "../chat.module.scss";
const MessagesList = ({ messages, onIntersection, isLastPage }) => {
const loadMoreEl = useRef();
useEffect(() => {
const observer = new IntersectionObserver(onIntersection);
if (loadMoreEl.current) {
observer.observe(loadMoreEl.current);
}
return () => {
observer.disconnect();
};
}, [messages]);
return (
<div className={styles.messageWrapper}>
{!isLastPage && (
<p ref={loadMoreEl} className="mt-2">
Cargando...
</p>
)}
{messages.map((message) => (
<Message message={message} key={message.id} />
))}
</div>
);
};
export default MessagesList;