-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Say I have two pages, and I want some condition to determine which one is rendered.
Essentially, what I'm looking for is a way to write if/else inside the render function. (In Angular terminology, I'm looking for an *ngIf equivalent). The docs and examples do not cover this.
The following example illustrates my best solution at present, using a range and a filter. However, it feels hacky and I am wondering whether something cleaner is intended.
let render_page1 = |state: &State| h1(("This is page 1"));
let render_page2 = |state: &State| h2(("This is page 2"));
let render = |state: &State| {
div((
button((on("click", |_| Msg::ToggleMyBoolean), "Toggle myBoolean")),
(0..1)
.filter(|_| state.myBoolean)
.map(|_| render_page1(state))
.collect::<Vec<_>>(),
(0..1)
.filter(|_| !state.myBoolean)
.map(|_| render_page2(state))
.collect::<Vec<_>>(),
))
};
By the way, great work on this crate! It is quite fun to play with. Cheers!
Metadata
Metadata
Assignees
Labels
No labels