use crate::{
children::{TypedChildrenFn, ViewFn},
IntoView,
};
use leptos_macro::component;
use reactive_graph::{computed::ArcMemo, traits::Get};
use tachys::either::Either;
#[component]
pub fn Show<W, C>(
children: TypedChildrenFn<C>,
when: W,
#[prop(optional, into)]
fallback: ViewFn,
) -> impl IntoView
where
W: Fn() -> bool + Send + Sync + 'static,
C: IntoView + 'static,
{
let memoized_when = ArcMemo::new(move |_| when());
let children = children.into_inner();
move || match memoized_when.get() {
true => Either::Left(children()),
false => Either::Right(fallback.run()),
}
}