error: API resolved without sending a response for /XXXX/XXXX, this may result in stalled requests.
I am trying to use Next.js' useSWR for data fetching, but I have been receiving an undefined response. Upon checking the console, I encountered the following error:
API resolved without sending a response for /XXXX/XXXX, this may result in stalled requests.
Below is how I am fetching the data using useSWR
const fetcher = (url) => axios(url).then(r => r.data);
const { data, error, isLoading } = useSWR(url, fetcher, {
fallbackData: article,
// revalidateOnFocus: false,
});
Admin
2023-05-30
From your code, I recommend adding handlers for data loading and validation using useSWR
. It provides a way to do that. Here's an example:
const { data, error, isLoading } = useSWR(url, fetcher, {
fallbackData: article,
// revalidateOnFocus: false,
});
if (error) return <>{error}</>;
if (isLoading) return <><h1>Loading</h1></>;
Regarding the cause of the error, it usually occurs when you don't return any response from that specific endpoint. Check the "/XXXX/XXXX/ and ensure that its returning a response when there is a request.
Privacy Policy
By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.