Function leptos::ErrorBoundary
source · pub fn ErrorBoundary<F, IV>(
cx: Scope,
props: ErrorBoundaryProps<F, IV>
) -> impl IntoViewwhere
F: Fn(Scope, RwSignal<Errors>) -> IV + 'static,
IV: IntoView,
Expand description
When you render a Result<_, _>
in your view, in the Err
case it will
render nothing, and search up through the view tree for an <ErrorBoundary/>
.
This component lets you define a fallback that should be rendered in that
error case, allowing you to handle errors within a section of the interface.
let (value, set_value) = create_signal(cx, Ok(0));
let on_input = move |ev| set_value(event_target_value(&ev).parse::<i32>());
view! { cx,
<input type="text" on:input=on_input/>
<ErrorBoundary
fallback=move |_, _| view! { cx, <p class="error">"Enter a valid number."</p>}
>
<p>"Value is: " {value}</p>
</ErrorBoundary>
}