Open History to see the last commit
1import React from 'react'
2import type { QueryCache } from '@tanstack/react-query'
3import { notifyManager } from '@tanstack/react-query'
4β
5const useSubscribeToQueryCache = <T>(
6 queryCache: QueryCache,
7 getSnapshot: () => T,
8 skip: boolean = false,
9): T => {
10 return React.useSyncExternalStore(
11 React.useCallback(
12 (onStoreChange) => {
13 if (!skip)
14 return queryCache.subscribe(notifyManager.batchCalls(onStoreChange))
15 return () => {
16 return
17 }
18 },
19 [queryCache, skip],
20 ),
21 getSnapshot,
22 getSnapshot,
23 )
24}
25β
26export default useSubscribeToQueryCache