swr: Error Catching not working with suspense true
useSWR catching errors is not working when adding to the options suspense true
The code will never enter the if the statement of the error and the website will carshes and If we remove the suspense true everything will work fine
const fetcher = url => Axios.get(url, authHeader()).then(res => res.data);
const url = `${apiUrl}/info/5`;
const { data, error, isValidating } = useSWR(url, fetcher, , { suspense: true });
if (error) {
console.log('error');
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
👍 BTW,
vercel/swrenables GitHub Discussions, so I think it’s the best place to post a question like this😄 https://github.com/vercel/swr/discussions@AmmarMohamadIsmaeel You can handle errors differently on each component by creating each ErrorBoundary or passing different props to a single ErrorBoundary.
or
Does it make sense?
@AmmarMohamadIsmaeel As the document describes, you have to use an error boundary instead of the error property.
https://swr.vercel.app/docs/suspense