-
Hello, I have an app with a lot of different mutations, but they all invalidate the same query key on success (and sometimes additional ones). Example: export const useCreateExport = (export_create: IExportCreate) => {
const queryClient = useQueryClient();
return useMutation<AxiosResponse, IStandardizedError>(() => createExport(export_create), {
onSuccess: () => queryClient.invalidateQueries([EAPI_ROUTES.TASKS]),
});
}; I'd like to find a way to configure it on the global QueryClient defaultOptions instead of each mutation, but I need a query client instance in the onSuccess 😬 Or maybe I should use the MutationCache ? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
thosil
May 26, 2022
Replies: 1 comment
-
Sometimes just explaining the issue gives some hint 😅 const queryClient = new QueryClient();
queryClient.setDefaultOptions({
...
mutations: {
onSuccess: () => queryClient.invalidateQueries([EAPI_ROUTES.TASKS]),
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
thosil
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes just explaining the issue gives some hint 😅
This is what I did and it looks like to work: