Skip to content

Commit 44fc7d5

Browse files
committed
added await to ensure updated queryData
1 parent 6e25c29 commit 44fc7d5

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/screens/UserPortal/Chat/Chat.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,29 +162,25 @@ export default function chat(): JSX.Element {
162162
}, [selectedContact]);
163163

164164
React.useEffect(() => {
165-
let isMounted = true;
166-
if (filterType === 'all') {
167-
chatsListRefetch().then(() => {
168-
if (isMounted && chatsListData?.chatsByUserId) {
165+
async function getChats(): Promise<void> {
166+
if (filterType === 'all') {
167+
await chatsListRefetch();
168+
if (chatsListData && chatsListData.chatsByUserId) {
169169
setChats(chatsListData.chatsByUserId);
170170
}
171-
});
172-
} else if (filterType === 'unread') {
173-
unreadChatListRefetch().then(() => {
174-
if (isMounted && unreadChatListData?.getUnreadChatsByUserId) {
171+
} else if (filterType === 'unread') {
172+
await unreadChatListRefetch();
173+
if (unreadChatListData && unreadChatListData.getUnreadChatsByUserId) {
175174
setChats(unreadChatListData.getUnreadChatsByUserId);
176175
}
177-
});
178-
} else if (filterType === 'group') {
179-
groupChatListRefetch().then(() => {
180-
if (isMounted && groupChatListData?.getGroupChatsByUserId) {
176+
} else if (filterType === 'group') {
177+
await groupChatListRefetch();
178+
if (groupChatListData && groupChatListData.getGroupChatsByUserId) {
181179
setChats(groupChatListData.getGroupChatsByUserId);
182180
}
183-
});
181+
}
184182
}
185-
return () => {
186-
isMounted = false;
187-
};
183+
getChats();
188184
}, [filterType]);
189185

190186
React.useEffect(() => {

0 commit comments

Comments
 (0)