pub struct SuspenseProps<Chil>{
pub fallback: ViewFnOnce,
pub children: TypedChildren<Chil>,
}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.
Each time one of the resources is loading again, it will fall back. To keep the current children instead, use Transition.
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 read
synchronously have
Some value in children. However, you can read resources asynchronously by using
Suspend.
async fn fetch_cats(how_many: u32) -> Vec<String> { vec![] }
let (cat_count, set_cat_count) = signal::<u32>(1);
let cats = Resource::new(move || cat_count.get(), |count| fetch_cats(count));
view! {
<div>
<Suspense fallback=move || view! { <p>"Loading (Suspense Fallback)..."</p> }>
// you can access a resource synchronously
{move || {
cats.get().map(|data| {
data
.into_iter()
.map(|src| {
view! {
<img src={src}/>
}
})
.collect_view()
})
}
}
// or you can use `Suspend` to read resources asynchronously
{move || Suspend::new(async move {
cats.await
.into_iter()
.map(|src| {
view! {
<img src={src}/>
}
})
.collect_view()
})}
</Suspense>
</div>
}§Required Props
- children:
TypedChildren<Chil>- Children will be rendered once initially to catch any resource reads, then hidden until all data have loaded.
§Optional Props
- fallback:
impl Into<ViewFnOnce>- A function that returns a fallback that will be shown while resources are still loading. By default this is an empty view.
Fields§
§fallback: ViewFnOnceA function that returns a fallback that will be shown while resources are still loading. By default this is an empty view.
children: TypedChildren<Chil>Children will be rendered once initially to catch any resource reads, then hidden until all data have loaded.
Implementations§
Source§impl<Chil> SuspenseProps<Chil>
impl<Chil> SuspenseProps<Chil>
Trait Implementations§
Auto Trait Implementations§
impl<Chil> Freeze for SuspenseProps<Chil>
impl<Chil> !RefUnwindSafe for SuspenseProps<Chil>
impl<Chil> Send for SuspenseProps<Chil>
impl<Chil> !Sync for SuspenseProps<Chil>
impl<Chil> Unpin for SuspenseProps<Chil>
impl<Chil> !UnwindSafe for SuspenseProps<Chil>
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
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>
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>
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