-
When I want to do an optimistic update, I will do const persistOptions = {
persister,
dehydrateOptions: {
shouldDehydrateQuery: (query) => { // not call after `setQueryData`
if (query.state.error) return false
if (query.state.fetchFailureReason) return false
if (!query.meta?.shouldPersist) return false
const queryIsReadyForPersistance = query.state.status === 'success'
if (queryIsReadyForPersistance) {
return !((query.state?.data as any)?.pages?.length > 1)
} else {
return false
}
},
},
} as Omit<PersistQueryClientOptions, 'queryClient'>
// MyApp
<PersistQueryClientProvider
client={queryClient}
persistOptions={persistOptions}>
{children}
</PersistQueryClientProvider> |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Sep 25, 2023
Replies: 1 comment 1 reply
-
Should work. Please show a reproduction |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Innei
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should work. Please show a reproduction