react-query-kit icon indicating copy to clipboard operation
react-query-kit copied to clipboard

What is the best practice for invalidating queries in react-query-kit

Open inceenes10 opened this issue 7 months ago • 4 comments

I generally use the approach in the code below.

import { queryClient } from "@sustable/system";

export const useDeleteUserMutation = createMutation({
	mutationKey: ["corporate", "user", "delete"],
	mutationFn: async (data: IDeleteUserRequest) => {
		await agent.delete("/user/delete", { data });
	},
	onSuccess: () =>
		queryClient.invalidateQueries({
			queryKey: ["corporate", "user", "list"],
		}),
});

This approach does not use useQueryClient() hook and I just wanna know if this approach has any side effect. If there is a side effect, what can I do to prevent that side effect? Is middleware like approach a better solution for this? If it is, could we add this to documentation of react-query-kit

Thank in advance.

inceenes10 avatar Jul 09 '24 18:07 inceenes10