Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

useSubscribeToQueryCache.ts

26 lines618 Bytes

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 )
25​
26export default useSubscribeToQueryCache