From 44fc7d55a09092a4dfe0a2cfc81504fdc2cd7381 Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Sun, 12 Jan 2025 22:39:25 +0530 Subject: [PATCH] added await to ensure updated queryData --- src/screens/UserPortal/Chat/Chat.tsx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/screens/UserPortal/Chat/Chat.tsx b/src/screens/UserPortal/Chat/Chat.tsx index b0b1734a40..5311d7faae 100644 --- a/src/screens/UserPortal/Chat/Chat.tsx +++ b/src/screens/UserPortal/Chat/Chat.tsx @@ -162,29 +162,25 @@ export default function chat(): JSX.Element { }, [selectedContact]); React.useEffect(() => { - let isMounted = true; - if (filterType === 'all') { - chatsListRefetch().then(() => { - if (isMounted && chatsListData?.chatsByUserId) { + async function getChats(): Promise { + if (filterType === 'all') { + await chatsListRefetch(); + if (chatsListData && chatsListData.chatsByUserId) { setChats(chatsListData.chatsByUserId); } - }); - } else if (filterType === 'unread') { - unreadChatListRefetch().then(() => { - if (isMounted && unreadChatListData?.getUnreadChatsByUserId) { + } else if (filterType === 'unread') { + await unreadChatListRefetch(); + if (unreadChatListData && unreadChatListData.getUnreadChatsByUserId) { setChats(unreadChatListData.getUnreadChatsByUserId); } - }); - } else if (filterType === 'group') { - groupChatListRefetch().then(() => { - if (isMounted && groupChatListData?.getGroupChatsByUserId) { + } else if (filterType === 'group') { + await groupChatListRefetch(); + if (groupChatListData && groupChatListData.getGroupChatsByUserId) { setChats(groupChatListData.getGroupChatsByUserId); } - }); + } } - return () => { - isMounted = false; - }; + getChats(); }, [filterType]); React.useEffect(() => {