diff --git a/src/chat/Chat.tsx b/src/chat/Chat.tsx index fde8a96..0bfeea5 100644 --- a/src/chat/Chat.tsx +++ b/src/chat/Chat.tsx @@ -77,35 +77,42 @@ export default function Chat(props: Props) { }; useEffect(() => { - loadChats() - }, []); + setChats([]); + setLoaded(false); + setLoading(false); + setTotalMessages(0); + }, [objectKey]); + + useEffect(() => { + if (chats.length === 0 && !loaded) { + loadChats(); + } + }, [objectKey, chats, loaded]); const loadMore = () => { loadChats(); }; return ( - - { loading && !loaded ? ( - - - - ) : ( - - - + + + {loading && !loaded ? ( + + - - - - - - )} - + ) : ( + + )} + + + + + + ); }