I have a Nextjs and ts application, which makes a request that calls a webhook from an integration that returns a Google sheet in a json array, I noticed that it is requesting from my integration continuously in a loop.
My code:
import { useQuery, UseQueryResult } from "@tanstack/react-query";
const useFetchData = <T>(url: string, queryKey: string): UseQueryResult<T> => {
return useQuery<T>({
queryKey: [queryKey],
queryFn: async () => {
console.log(`Fetching data from: ${url}`);
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
const data = await response.json();
console.log("Data fetched:", data);
return data;
},
});
};
export default useFetchData;
I put logs and the page is not there being re-rendered again, only the request occurs again and again.I couldn’t identify the reason for this.
New contributor
Henrique Sanches Silva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.