You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you get an error, you can log it and show an alternate user interface.
645
621
622
+
#### `<ErrorBoundary />`
623
+
624
+
Catching errors is only enabled on the client, and is ignored when rendering on the server. This is done intentionally, because on the server, when rendering to a stream, we cannot take back the HTML that has already been sent.
625
+
626
+
```tsx
627
+
const Broken =component(() => {
628
+
thrownewError();
629
+
});
630
+
631
+
const App =component(() => {
632
+
return (
633
+
<>
634
+
<div>I'm OK 🙃</div>
635
+
<ErrorBoundaryfallback={<div>Ooops! 😳</div>}>
636
+
<Broken />
637
+
</ErrorBoundary>
638
+
<div>I'm OK too 😘</div>
639
+
</>
640
+
);
641
+
});
642
+
```
643
+
644
+
`<ErrorBoundary />` also has a `renderFallback` and `onError` prop.
If your application is structured into separate modules, you may wish to employ lazy loading for efficiency. This can be achieved through code splitting. To implement lazy loading for components, dynamic imports of the component must be wrapped in a specific function - `lazy`. Additionally, a `Suspense` component is required to display a loading indicator or skeleton screen until the module has been fully loaded.
0 commit comments