const { isLoading, error, data } = useQuery(["click"], () =>
makeRequest.get("/example/1234").then((res) => {
return res.data;
})
);
const Path = async (postId, cardNickNameId) => {
const promise = async () => {
try {
const res = await makeRequest.post("/elpmaxe", {
postId: postId,
cardNickNameId: cardNickNameId,
});
queryClient.invalidateQueries(["click"]); //<------ BAD!
console.log(res);
return Promise.resolve(res.data);
} catch (error) {
console.log(error);
return Promise.reject(error.res.data);
}
};
const success = PromisseSucess("Assinando com sucesso!").success;
//prettier-ignore
const pending = PromisseLoading("Subscribing you to the best plan.").pending;
//prettier-ignore
const error = PromisseError("You need add a payment method or choose a card!").error;
const toastOptions = {
success,
pending,
error,
};
toast.promise(promise, toastOptions);
};
When he makes the GET request, he searches for my database data, this data is usually updated a lot, so I always need to invalidate the queries to have fresh data. If I put the invalidation that way it runs too fast and doesn't work, the setTimeout worked fine but it's a terrible bad practice, I don't want to use it. the goal is that when I use queryClient.invalidateQueries(["click"]) it will update the data and get it to me with GET