An error boundary is a React feature that lets you wrap part of your UI, and if an error occurs within that boundary, you display some fallback UI (such as an error message for the user).
SWAN provides an in-box utility component for this. It even accepts a prop called fallback
if you want your custom handling; otherwise, SWAN will show the error details. You also have the option to see your custom fallback as well as error details, by passing true
to the boolean prop forceShowError
.
The preview has been updated.
Props
ErrorBoundary
This component is implemented using the
<div />
as the root element. You can utilize the native attributes supported by <div />
tag. The ref
is directly assigned to the root element, allowing you to access and manipulate it as needed.See core props for additional props that can be applied to this component.
prop | type | required | description | default |
---|---|---|---|---|
fallback | ReactNode | false | A React node that serves as a fallback UI when an error occurs. | null |
forceShowError | boolean | false | A boolean indicating whether to force showing the error details | null |
errorDetailMsg | string | null | false | Context or a message related to the error. | null |