Promises
Handling Rejected Promises
If a promise streamed from server to client rejects, it can be caught by an ErrorBoundary. This example shows how to do that.
What happens here? The getData
function returns a Promise that is rejected after a delay. When that happens, our Suspense
fallback is replaced with the ErrorFallback
component. This is a much better user experience than showing a whole page error message, which is what happens when you don't catch the error.
Live Demo
This example can't be easily inlined as it demonstrates how a full-page feels to the end user. Here it is inside an iframe, and there's a looping video below too.
Video Preview
In case the iframe doesn't work for some reason, this is a looping video of what you would see. Click the video to open the full page example in a new tab.