How do I make sure an error from a resource gets caught by a higher level error boundary? #1862
Answered
by
gbj
SleeplessOne1917
asked this question in
Q&A
-
Suppose I have a component like this: #[component]
fn MyComponent() -> impl IntoView {
let my_resource = create_resource(/* resource fetching stuff */); // resource for a result
provide_context(my_resource);
view! {
<Suspense>
<ErrorBoundary> {/* I want to catch errors for the resource here*/}
{/* Several nested components later*/}
<ErrorBoundary>
<NestedComponent /> {/* This component uses the resource defined above via use_context*/}
</ErrorBoundary>
{/* Several nested components later*/}
</ErrorBoundary>
</Suspense>
}
} How do I make sure an error from the resource gets handled at the error boundary I marked in the code snippet? |
Beta Was this translation helpful? Give feedback.
Answered by
gbj
Oct 8, 2023
Replies: 1 comment
-
Very simply: an So:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
SleeplessOne1917
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very simply: an
ErrorBoundary
is triggered if you render anErr(_)
inside it.So:
my_resource.and_then(|_| ())
to render eitherOk(())
(shows nothing) orErr(_)
(triggers error boundary).unwrap_or_else()
the Result to some default value such that it can never renderErr
under those children