1use crate::{
2 children::{TypedChildrenFn, ViewFn},
3 IntoView,
4};
5use leptos_macro::component;
6use reactive_graph::{computed::ArcMemo, traits::Get};
7use tachys::either::Either;
8
9#[component(transparent)]
10pub fn Show<W, C>(
11 children: TypedChildrenFn<C>,
13 when: W,
15 #[prop(optional, into)]
17 fallback: ViewFn,
18) -> impl IntoView
19where
20 W: Fn() -> bool + Send + Sync + 'static,
21 C: IntoView + 'static,
22{
23 let memoized_when = ArcMemo::new(move |_| when());
24 let children = children.into_inner();
25
26 move || match memoized_when.get() {
27 true => Either::Left(children()),
28 false => Either::Right(fallback.run()),
29 }
30}