I have a simple use case where I'm fetching data from an api based on the value of the router.query in NEXT JS.
const { data, error } = useSWR(() => {
if (router.query.sort === "shortest")
return `http://localhost:1337/api/playlists/${options?.value}?sortBy=duration`;
if (router.query.sort === "longest")
return `http://localhost:1337/api/playlists/${options?.value}?sortBy=duration&order=desc`;
if (router.query.sort === "oldest")
return `http://localhost:1337/api/playlists/${options?.value}?sortBy=id`;
return `http://localhost:1337/api/playlists/${options?.value}?sortBy=id&order=desc`;
});
When an error occurs in any one of the api endpoints, instead of reading directly the error as listed above, I found that it's returned undefined but instead another {data,error} is nested inside the data that is first returned which is different from what the docs describes. Hopefully my description is clear enough. Please clarify if I'm doing anything wrong here
I have a simple use case where I'm fetching data from an api based on the value of the router.query in NEXT JS.
When an error occurs in any one of the api endpoints, instead of reading directly the error as listed above, I found that it's returned undefined but instead another {data,error} is nested inside the data that is first returned which is different from what the docs describes. Hopefully my description is clear enough. Please clarify if I'm doing anything wrong here