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

useIsRestoring.ts

26 lines862 Bytes

1import { getIsRestoringContext } from './context.js'
2import type { Box } from './containers.svelte.js'
3​
4/**
5 * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` function alongside it to
6 * check if a restore is currently in progress. `createQuery` and friends also check this internally to avoid
7 * race conditions between the restore and mounting queries.
8 *
9 * @returns A reactive box β€” read `.current` for `true` while a persisted client is being restored, `false`
10 * otherwise.
11 * @example
12 * ```svelte
13 * <script lang="ts">
14 * import { useIsRestoring } from '@tanstack/svelte-query'
15 *
16 * const isRestoring = useIsRestoring()
17 * </script>
18 *
19 * {#if isRestoring.current}
20 * <div>Restoring cached data...</div>
21 * {/if}
22 * ```
23 */
24export function useIsRestoring(): Box<boolean> {
25 return getIsRestoringContext()