pub trait Throw<S = ()>: Sized {
    type Out;

    fn throw(self, cx: &ScopeState) -> Option<Self::Out>;
    fn throw_with<D: Debug + 'static>(
        self,
        cx: &ScopeState,
        e: impl FnOnce() -> D
    ) -> Option<Self::Out>; }
Expand description

A trait to allow results to be thrown upwards to the nearest Error Boundary

The canonical way of using this trait is to throw results from hooks, aborting rendering through question mark synax. The throw method returns an option that evalutes to None if there is an error, injecting the error to the nearest error boundary.

If the value is Ok, then throw returns the value, not aborting the rendering preocess.

The call stack is saved for this component and provided to the error boundary


#[inline_props]
fn app(cx: Scope, count: String) -> Element {
    let id: i32 = count.parse().throw(cx)?;

    cx.render(rsx! {
        div { "Count {}" }
    })
}

Required Associated Types§

The value that will be returned in if the given value is Ok.

Required Methods§

Returns an option that evalutes to None if there is an error, injecting the error to the nearest error boundary.

If the value is Ok, then throw returns the value, not aborting the rendering preocess.

The call stack is saved for this component and provided to the error boundary

Note that you can also manually throw errors using the throw method on ScopeState directly, which is what this trait shells out to.


#[inline_props]
fn app(cx: Scope, count: String) -> Element {
    let id: i32 = count.parse().throw(cx)?;

    cx.render(rsx! {
        div { "Count {}" }
    })
}

Returns an option that evalutes to None if there is an error, injecting the error to the nearest error boundary.

If the value is Ok, then throw returns the value, not aborting the rendering preocess.

The call stack is saved for this component and provided to the error boundary

Note that you can also manually throw errors using the throw method on ScopeState directly, which is what this trait shells out to.


#[inline_props]
fn app(cx: Scope, count: String) -> Element {
    let id: i32 = count.parse().throw(cx)?;

    cx.render(rsx! {
        div { "Count {}" }
    })
}

Implementations on Foreign Types§

We call clone on any errors that can be owned out of a reference

Or just throw errors we know about

Or just throw errors we know about

Implementors§