How to use persistQueryClient? #78
Replies: 5 comments 8 replies
-
As in React, I guess. Provide the function what it needs. |
Beta Was this translation helpful? Give feedback.
-
Ok, this is what i currently have. But it doesn't seem to be working const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: Infinity,
refetchOnWindowFocus: false
}
}
});
const persister = createSyncStoragePersister({
storage: window.localStorage,
serialize: (data) => compress(JSON.stringify(data)),
deserialize: (data) => JSON.parse(decompress(data))
});
persistQueryClient({ queryClient, persister: persister , maxAge: Infinity });
persistQueryClientRestore({ queryClient, persister: persister }); and providers: [
provideQueryClient(queryClient)
] |
Beta Was this translation helpful? Give feedback.
-
Can you provide a stackblitz, please? |
Beta Was this translation helpful? Give feedback.
-
@MaximilianLloyd did you manage to make it work? |
Beta Was this translation helpful? Give feedback.
-
@NetanelBasal Wouldn't it be better to wrap this stuff into a export const provideQueryClientPersistance = (persister) => {
return {
provide: ENVIRONMENT_INITIALIZER,
multi: true,
useValue() {
const queryClient = inject(QueryClientService);
persistQueryClient({ queryClient, persister: persister , maxAge: Infinity });
persistQueryClientRestore({ queryClient, persister: persister });
},
};
} const persister = createSyncStoragePersister({
storage: window.localStorage,
serialize: (data) => compress(JSON.stringify(data)),
deserialize: (data) => JSON.parse(decompress(data))
});
bootstrapApplication(AppComponent, {
providers: [
provideQueryClientOptions({
defaultOptions: {
queries: {
staleTime: Infinity,
refetchOnWindowFocus: false
}
}
}),
provideQueryClientPersistance(persister)
],
}); |
Beta Was this translation helpful? Give feedback.
-
Hi. I was wondering how you can use the persistQueryClient functionality with this?
Beta Was this translation helpful? Give feedback.
All reactions