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

useIsRestoring.ts

28 lines883 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
6 * `useIsRestoring` function alongside it to check if a restore is currently in
7 * progress. `createQuery` and friends also check this internally to avoid race
8 * conditions between the restore and mounting queries.
9 *
10 * @example
11 * ;```svelte
12 * <script lang="ts">
13 * import { useIsRestoring } from '@tanstack/svelte-query'
14 *
15 * const isRestoring = useIsRestoring()
16 * </script>
17 *
18 * {#if isRestoring.current}
19 * <div>Restoring cached data...</div>
20 * {/if}
21 * ```
22 *
23 * @returns A reactive box β€” read `.current` for `true` while a persisted client
24 * is being restored, `false` otherwise.
25 */
26export function useIsRestoring(): Box<boolean> {
27 return getIsRestoringContext()