pub fn ShowLet<T, ChFn, V, M, __ImplTrait0>(
props: ShowLetProps<T, ChFn, V, M, __ImplTrait0>,
) -> impl IntoViewwhere
__ImplTrait0: IntoOptionGetter<T, M>,
ChFn: Fn(T) -> V + Send + Clone + 'static,
V: IntoView + 'static,
T: 'static,Expand description
Like <Show> but for Option. This is a shortcut for
ⓘ
value.map(|value| {
view! { ... }
})If you specify a fallback it is equvalent to
ⓘ
value
.map(
|value| children(value),
)
.unwrap_or_else(fallback)§Example
let (opt_value, set_opt_value) = signal(None::<i32>);
view! {
<ShowLet some=opt_value let:value>
"We have a value: " {value}
</ShowLet>
}You can also specify a fallback:
let (opt_value, set_opt_value) = signal(None::<i32>);
view! {
<ShowLet some=opt_value let:value fallback=|| "Got nothing">
"We have a value: " {value}
</ShowLet>
}In addition to signals you can also use a closure that returns an Option:
let (opt_value, set_opt_value) = signal(None::<i32>);
view! {
<ShowLet some=move || opt_value.get().map(|v| v * 2) let:value>
"We have a value: " {value}
</ShowLet>
}§Required Props
- children: [
ChFn]-
The children will be shown whenever
valueisSome.They take the inner value as an argument. Use
let:to bind the value to a variable.
-
- some: [
__ImplTrait0]- A signal of type
Optionor a closure that returns anOption. If the value isSome, the children will be shown. Otherwise the fallback will be shown, if present.
- A signal of type
§Optional Props
- fallback:
impl Into<ViewFn>-
A closure that returns what gets rendered when the value is
None. By default this is the empty view.You can think of it as the closure inside
.unwrap_or_else(|| fallback()).
-
- _marker:
PhantomData<(T, M)>- Marker for generic parameters. Ignore this.