Error Catching not working with suspense true
See original GitHub issueuseSWR 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');
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:15
Top Results From Across the Web
Catch Your Suspense Errors - chan.dev
Catch Your Suspense Errors. Not every promise resolves. Some are rejected. So, when we use React.Suspense to show loading and loaded states,
Read more >With React 18 and suspense, how to display specific errors ...
Probably the most tricky part is how to trigger the error to be checked, especially since the code is using async\await . Check...
Read more >React Suspense Error Handling and Post Requests - YouTube
Learn how to fetch new data, handle errors, and do post request with Suspense in React.
Read more >Suspense - SWR
SWR is a React Hooks library for data fetching. SWR first returns the data from cache (stale), then sends the fetch request (revalidate),...
Read more >Error Boundaries - React
To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. Error boundaries are React components that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👍 BTW,
vercel/swr
enables 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?