FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    suspense

    function · ferroui-view · v0.5.0

    fn suspense<T: Clone + 'static>(state: crate::reactive::Signal<AsyncState<T>>, pending: impl Fn() -> crate::element::Element + 'static, ready: impl Fn(T) -> crate::element::Element + 'static, failed: impl Fn(String) -> crate::element::Element + 'static) -> crate::element::Element
    

    An element that follows state: the element of pending() while it is pending, of ready(value) once it is ready, and of failed(message) once it failed. It is a component that runs again when the state changes; the reconciler patches what the closures return, so the elements of two states with the same controls keep them.

    let people = use_future(query.get(), |query| load_people(query.clone()));
    suspense(
        people,
        || rsx! { TextBlock { text: "Loading..." } },
        |people| rsx! { ListBox { for p in &people { ListBoxItem { key: p.id, content: p.name.clone() } } } },
        |error| rsx! { TextBlock { text: error } },
    )
    

    View source

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.