Replies: 1 comment 2 replies
-
Right now I think the best way to do this would be to leverage a small client side cache of loader data you could return if the fetch fails. You would probably then want to clear the cache when the route component unmounts from a async function loader() {
try {
// Always try to get latest and stick it in a cache
let data = await fetchData();
cache.set(key, data);
return data;
} catch (e) {
let data = cache.get(data);
if (data) {
// If our fetch failed but we have stale data, use it
return data;
}
// Otherwise re-throw the error to trigger the ErrorBoundary
throw e;
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have this small and simple component and I use it as a dashboard for a user.
The component data refreshes every 30 seconds, but if it fails I wish to keep showing users the old data which is already there (with a tiny message maybe, that the data is stale) because the next request might succeed.
What should I do? Am I using perhaps the wrong method for this kind of task?
I'd love for some help/tips 😊 please
Beta Was this translation helpful? Give feedback.
All reactions