pub struct AwaitProps<T, Fut, Chil, V>where
T: Send + Sync + Serialize + DeserializeOwned + 'static,
Fut: Future<Output = T> + Send + 'static,
Chil: FnOnce(&T) -> V + Send + 'static,
V: IntoView + 'static,{
pub future: Fut,
pub blocking: bool,
pub children: Chil,
}Expand description
Props for the Await component.
Allows you to inline the data loading for an async block or
server function directly into your view. This is the equivalent of combining a
[create_resource] that only loads once (i.e., with a source signal || ()) with
a Suspense with no fallback.
Adding let:{variable name} to the props makes the data available in the children
that variable name, when resolved.
async fn fetch_monkeys(monkey: i32) -> i32 {
// do some expensive work
3
}
view! {
<Await
future=fetch_monkeys(3)
let:data
>
<p>{*data} " little monkeys, jumping on the bed."</p>
</Await>
}§Required Props
- future: [
Fut]- A
Futurethat will the component will.awaitbefore rendering.
- A
- children: [
Chil]-
A function that takes a reference to the resolved data from the
futurerenders a view.§Syntax
This can be passed in the
viewchildren of the<Await/>by using thelet:syntax to specify the name for the data variable.view! { <Await future=fetch_monkeys(3) let:data > <p>{*data} " little monkeys, jumping on the bed."</p> </Await> }is the same as
view! { <Await future=fetch_monkeys(3) children=|data| view! { <p>{*data} " little monkeys, jumping on the bed."</p> } /> }
-
§Optional Props
- blocking:
bool- If
true, the component will create a blocking resource, preventing the HTML stream from returning anything beforefuturehas resolved.
- If
Fields§
§future: FutA Future that will the component will .await
before rendering.
blocking: boolIf true, the component will create a blocking resource, preventing
the HTML stream from returning anything before future has resolved.
children: ChilA function that takes a reference to the resolved data from the future
renders a view.
§Syntax
This can be passed in the view children of the <Await/> by using the
let: syntax to specify the name for the data variable.
view! {
<Await
future=fetch_monkeys(3)
let:data
>
<p>{*data} " little monkeys, jumping on the bed."</p>
</Await>
}is the same as
view! {
<Await
future=fetch_monkeys(3)
children=|data| view! {
<p>{*data} " little monkeys, jumping on the bed."</p>
}
/>
}Implementations§
Source§impl<T, Fut, Chil, V> AwaitProps<T, Fut, Chil, V>
impl<T, Fut, Chil, V> AwaitProps<T, Fut, Chil, V>
Trait Implementations§
Source§impl<T, Fut, Chil, V> Props for AwaitProps<T, Fut, Chil, V>
impl<T, Fut, Chil, V> Props for AwaitProps<T, Fut, Chil, V>
Auto Trait Implementations§
impl<T, Fut, Chil, V> Freeze for AwaitProps<T, Fut, Chil, V>
impl<T, Fut, Chil, V> RefUnwindSafe for AwaitProps<T, Fut, Chil, V>where
Fut: RefUnwindSafe,
Chil: RefUnwindSafe,
impl<T, Fut, Chil, V> Send for AwaitProps<T, Fut, Chil, V>
impl<T, Fut, Chil, V> Sync for AwaitProps<T, Fut, Chil, V>
impl<T, Fut, Chil, V> Unpin for AwaitProps<T, Fut, Chil, V>
impl<T, Fut, Chil, V> UnwindSafe for AwaitProps<T, Fut, Chil, V>where
Fut: UnwindSafe,
Chil: UnwindSafe,
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