Skip to content

Commit

Permalink
remove event listener on return
Browse files Browse the repository at this point in the history
  • Loading branch information
anguyen-yext2 committed Jan 3, 2025
1 parent b11400c commit f0ccf0c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/ChatPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,18 @@ export function ChatPanel(props: ChatPanelProps) {

useLayoutEffect(() => {
const curr = messagesContainer.current;
curr?.addEventListener("scroll", () => {
const onScroll = () => {
if (!conversationId) {
return;
}
saveSessionState(conversationId, {
scrollPosition: curr.scrollTop,
scrollPosition: curr?.scrollTop,
});
});
}
curr?.addEventListener("scroll", onScroll);
return () => {
curr?.removeEventListener("scroll", onScroll);
};
}, [messagesContainer, conversationId]);

return (
Expand Down

0 comments on commit f0ccf0c

Please sign in to comment.