Skip to content

Commit f8968c0

Browse files
authored
fix: properly resolve activeQueryType state (#3004)
1 parent a9397c4 commit f8968c0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const usePaginatedChannels = <
6666
}: Parameters<StreamChatGenerics>) => {
6767
const [error, setError] = useState<Error | undefined>(undefined);
6868
const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
69-
const activeQueryType = useRef<QueryType | null>('queryLocalDB');
69+
const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');
7070
const activeChannels = useActiveChannelsRefContext();
7171
const isMountedRef = useIsMountedRef();
7272
const { client } = useChatContext<StreamChatGenerics>();
@@ -114,7 +114,7 @@ export const usePaginatedChannels = <
114114
setError(undefined);
115115
activeRequestId.current++;
116116
const currentRequestId = activeRequestId.current;
117-
activeQueryType.current = queryType;
117+
setActiveQueryType(queryType);
118118

119119
const newOptions = {
120120
limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,
@@ -152,7 +152,7 @@ export const usePaginatedChannels = <
152152
// querying.current check is needed in order to make sure the next query call doesnt flick an error
153153
// state and then succeed (reconnect case)
154154
if (retryCount === MAX_NUMBER_OF_RETRIES && !isQueryingRef.current) {
155-
activeQueryType.current = null;
155+
setActiveQueryType(null);
156156
console.warn(err);
157157

158158
setError(
@@ -166,7 +166,7 @@ export const usePaginatedChannels = <
166166
return queryChannels(queryType, retryCount + 1);
167167
}
168168

169-
activeQueryType.current = null;
169+
setActiveQueryType(null);
170170
};
171171

172172
const refreshList = async () => {
@@ -229,7 +229,7 @@ export const usePaginatedChannels = <
229229
return false;
230230
}
231231

232-
activeQueryType.current = null;
232+
setActiveQueryType(null);
233233

234234
return true;
235235
};
@@ -279,7 +279,7 @@ export const usePaginatedChannels = <
279279
error,
280280
hasNextPage,
281281
loadingChannels:
282-
activeQueryType.current === 'queryLocalDB'
282+
activeQueryType === 'queryLocalDB'
283283
? true
284284
: // Although channels.length === 0 should come as a given when we have !channelListInitialized,
285285
// due to the way offline storage works currently we have to do this additional
@@ -290,7 +290,7 @@ export const usePaginatedChannels = <
290290
pagination?.isLoading || (!channelListInitialized && channels.length === 0),
291291
loadingNextPage: pagination?.isLoadingNext,
292292
loadNextPage: channelManager.loadNext,
293-
refreshing: activeQueryType.current === 'refresh',
293+
refreshing: activeQueryType === 'refresh',
294294
refreshList,
295295
reloadList,
296296
staticChannelsActive,

0 commit comments

Comments
 (0)