I have two queries
one for single user
const { data: user, error, isLoading } = useQuery<User>(
['users', userId],
() => axios.get('/users/' + userId).then((res) => res.data),
{
retry: false,
}
);
and for list of all users
const { data: users, error, isLoading } = useQuery<User[]>(
['users'],
() => axios.get('/users').then((res) => res.data),
{
retry: false,
}
);
Now I have delete mutation
const deleteMutation = useMutation(
() => axios.delete('api/v1/users/' + userId),
{
onSuccess: () => {
toast.success(`successfully deleted`);
resetForm();
},
onError: (error: AxiosError) => {
toast.error(`Failed to delete ${error.message}`);
resetForm();
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['users'] });
},
}
);
Issue is that after deletion it invalidates both list of users and single user that couses unnesesary 404.
What is proper way to prevent invalidating single user query after delete mutation?