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

isRestoring.ts

19 lines856 Bytes

1import { createContext, useContext } from 'solid-js'
2import type { Accessor } from 'solid-js'
3​
4const IsRestoringContext = createContext<Accessor<boolean>>(() => false)
5​
6/**
7 * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` primitive alongside it to
8 * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
9 * race conditions between the restore and mounting queries.
10 *
11 * @returns An accessor that reads `true` while a persisted client is being restored, `false` otherwise.
12 */
13export const useIsRestoring = () => useContext(IsRestoringContext)
14​
15/**
16 * The Provider that `PersistQueryClientProvider` uses to signal whether a persisted client is currently
17 * being restored, read by `useIsRestoring`.
18 */
19export const IsRestoringProvider = IsRestoringContext.Provider