feat: add query provider for Tanstack
This commit is contained in:
17
src/app/providers/QueryProvider.svelte
Normal file
17
src/app/providers/QueryProvider.svelte
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
/**
|
||||||
|
* Query Provider Component
|
||||||
|
*
|
||||||
|
* All components that use useQueryClient() or createQuery() must be
|
||||||
|
* descendants of this provider.
|
||||||
|
*/
|
||||||
|
import { queryClient } from '$shared/api/queryClient';
|
||||||
|
import { QueryClientProvider } from '@tanstack/svelte-query';
|
||||||
|
|
||||||
|
/** Slot content for child components */
|
||||||
|
let { children } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
{@render children?.()}
|
||||||
|
</QueryClientProvider>
|
||||||
26
src/shared/api/queryClient.ts
Normal file
26
src/shared/api/queryClient.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { QueryClient } from '@tanstack/query-core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query client instance
|
||||||
|
*/
|
||||||
|
export const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
/**
|
||||||
|
* Default staleTime: 5 minutes
|
||||||
|
*/
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
/**
|
||||||
|
* Default gcTime: 10 minutes
|
||||||
|
*/
|
||||||
|
gcTime: 10 * 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: true,
|
||||||
|
retry: 3,
|
||||||
|
/**
|
||||||
|
* Exponential backoff
|
||||||
|
*/
|
||||||
|
retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, 30000),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user