Struct leptos::SuspenseProps
source · pub struct SuspenseProps<V>where
V: IntoView + 'static,{
pub fallback: ViewFn,
pub children: Rc<dyn Fn() -> V>,
}
Expand description
Props for the Suspense
component.
If any Resource
is read in the children
of this
component, it will show the fallback
while they are loading. Once all are resolved,
it will render the children
.
Note that the children
will be rendered initially (in order to capture the fact that
those resources are read under the suspense), so you cannot assume that resources have
Some
value in children
.
async fn fetch_cats(how_many: u32) -> Option<Vec<String>> { Some(vec![]) }
let (cat_count, set_cat_count) = create_signal::<u32>(1);
let cats = create_resource(move || cat_count.get(), |count| fetch_cats(count));
view! {
<div>
<Suspense fallback=move || view! { <p>"Loading (Suspense Fallback)..."</p> }>
{move || {
cats.get().map(|data| match data {
None => view! { <pre>"Error"</pre> }.into_view(),
Some(cats) => cats
.iter()
.map(|src| {
view! {
<img src={src}/>
}
})
.collect_view(),
})
}
}
</Suspense>
</div>
};
§Required Props
- children: [
Rc<dyn Fn() -> V>
]- Children will be displayed once all
async
Resource
s have resolved.
- Children will be displayed once all
§Optional Props
- fallback:
impl Into<ViewFn>
- Returns a fallback UI that will be shown while
async
Resource
s are still loading. By default this is the empty view.
- Returns a fallback UI that will be shown while
Fields§
§fallback: ViewFn
Returns a fallback UI that will be shown while async
Resource
s are still loading. By default this is the empty view.
children: Rc<dyn Fn() -> V>
Children will be displayed once all async
Resource
s have resolved.
Implementations§
source§impl<V> SuspenseProps<V>where
V: IntoView + 'static,
impl<V> SuspenseProps<V>where
V: IntoView + 'static,
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for SuspenseProps<V>
impl<V> !RefUnwindSafe for SuspenseProps<V>
impl<V> !Send for SuspenseProps<V>
impl<V> !Sync for SuspenseProps<V>
impl<V> Unpin for SuspenseProps<V>
impl<V> !UnwindSafe for SuspenseProps<V>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more