T
TanStack13mo ago
exotic-emerald

Make onsuccess in queryClient specific to some queries only

Help I want this onSuccess to only run for queries with id userData, how do I ensure that? I read the entire blog, it doesn't address this
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: Infinity,
}
},
queryCache: new QueryCache({
onSuccess: (data, query) => { // This should only run for "userData" queries ... how?
userDataStore.set.state(draft => data as any as UserData);
}
})

});
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: Infinity,
}
},
queryCache: new QueryCache({
onSuccess: (data, query) => { // This should only run for "userData" queries ... how?
userDataStore.set.state(draft => data as any as UserData);
}
})

});
My goal is simply to sync with my zustand store when the first "userData" query finishes.
Breaking React Query's API on purpose
Why good API design matters, even if it means breaking existing APIs in the face of resistance.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?