Skip to content

Commit 7bb75b4

Browse files
Merge pull request #1163 from GetStream/vishal/channel-list-fix
fix: usePaginatedChannels hook fixes
2 parents b759c2d + c184844 commit 7bb75b4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

package/src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const usePaginatedChannels = <
5050
const [activeQueryType, setActiveQueryType] = useState<QueryType | null>();
5151
const isMountedRef = useIsMountedRef();
5252
const filtersRef = useRef<typeof filters | null>(null);
53-
const sortRef = useRef<typeof filters | null>(null);
53+
const sortRef = useRef<typeof sort | null>(null);
5454
const activeRequestId = useRef<number>(0);
5555

5656
const queryChannels: QueryChannels = async (
@@ -59,14 +59,14 @@ export const usePaginatedChannels = <
5959
): Promise<void> => {
6060
if (!client || !isMountedRef.current) return;
6161

62-
const hasUpdatedData = () =>
62+
const hasUpdatedData =
63+
queryType === 'loadChannels' ||
6364
[
6465
JSON.stringify(filtersRef.current) !== JSON.stringify(filters),
6566
JSON.stringify(sortRef.current) !== JSON.stringify(sort),
66-
activeRequestId.current !== currentRequestId,
67-
].some(Boolean); // will return true if any element is truthy
67+
].some(Boolean);
6868

69-
const queryIsStale = () => !isMountedRef || activeRequestId.current !== currentRequestId;
69+
const isQueryStale = () => !isMountedRef || activeRequestId.current !== currentRequestId;
7070

7171
/**
7272
* We don't need to make another call to query channels if we don't
@@ -77,6 +77,7 @@ export const usePaginatedChannels = <
7777
}
7878

7979
filtersRef.current = filters;
80+
sortRef.current = sort;
8081
isQueryingRef.current = true;
8182
setError(undefined);
8283
activeRequestId.current++;
@@ -94,7 +95,7 @@ export const usePaginatedChannels = <
9495
skipInitialization: activeChannels.current,
9596
});
9697

97-
if (queryIsStale() || !isMountedRef.current) {
98+
if (isQueryStale() || !isMountedRef.current) {
9899
return;
99100
}
100101

@@ -113,7 +114,7 @@ export const usePaginatedChannels = <
113114
isQueryingRef.current = false;
114115
await waitSeconds(2);
115116

116-
if (queryIsStale()) {
117+
if (isQueryStale()) {
117118
return;
118119
}
119120

0 commit comments

Comments
 (0)