Open History to see the last commit
1import { MutationCache, QueryClient } from '@tanstack/lit-query'
2import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
3import { moviesMutations, moviesQueries } from './services/movies/queries'
4import { toast } from './toast'
5β
6export const persister = createAsyncStoragePersister({
7 storage: window.localStorage,
8})
9β
10export const queryClient = new QueryClient({
11 defaultOptions: {
12 queries: {
13 gcTime: 24 * 60 * 60 * 1000, // 24 hours
14 staleTime: 2000,
15 retry: 0,
16 },
17 },
18 // configure global cache callbacks to show error toast notifications
19 mutationCache: new MutationCache({
20 onError: (error) => {
21 toast.error(error.message)
22 },
23 }),
24})
25β
26// we need a default mutation function so that paused mutations can resume after a page reload
27queryClient.setMutationDefaults(moviesQueries.all(), {
28 ...moviesMutations.update(),
29 onSuccess: (data) => {
30 toast.success(data.message)
31 },
32})