making error boundary optional or less coupled from suspense #2043
Unanswered
intergalacticspacehighway
asked this question in
Ideas
Replies: 1 comment
-
Seems good to me... I am currently struggling a bit since I have to wrap a lot of mini components with error boundary. I have an HOC for that, but still it's a bit annoying to do everywhere that I am using suspense and that might error. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there 👋
I want to discuss some use cases where keeping
ErrorBoundary
optional might make sense.Example
As shown below,
B
is usinguseSWR
with suspense enabled,ErrorBoundary
wrappingB
is responsible to catch errors.Simple ErrorBoundary
This usecase makes sense and has no issues.
ErrorBoundary with a retry button
In this example, it becomes a bit of a problem to pass retry functionality to
ErrorBoundary
. We can use global mutate but IMO won't be very neat.ErrorBoundary that shows error message along with previously fetched data.
This becomes a bit inconvenient as the UI is defined in
B
and we need to show data along with an error message.Suggestions
A boolean argument named maybe
errorBoundary
in hook similar tosuspense
.errorBoundary Behaviour
true
orsuspense
istrue
, all errors will be thrown to the error boundary.false
andsuspense
isfalse
, errors are returned as state.false
andsuspense
istrue
, errors are returned as state.References
useErrorBoundary
that can be useful to opt out ofErrorBoundary
.Alternatives
Let me know if it makes sense or if there is a better approach to handle this.
Beta Was this translation helpful? Give feedback.
All reactions