-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional rendering #19
Comments
The correct thing is to use html("div", {
.children_signal_vec(state.path.signal_cloned()
.map({
let state = Rc::clone(self);
move |path| {
match path.as_str() {
"/foo" => {
vec![
html("div", {
.text("foo page!")
})
]
}
"/bar" => {
vec![
html("div", {
.text("bar page!")
})
]
}
_ => {
vec![
html("div", {
.text("error page!")
})
]
}
}
}
})
.to_signal_vec())
}) Since the signal returns a |
Ah nice! I missed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm wondering what is a good way to render dom nodes conditionally, based on a signal.
For example to render different sub pages, based on the current "route" (document.location). In such a case only the current sub page should be added the document, and when the route changes, it should be replaced.
I can use a
SignalVec
, with each entry representing a different state, and then render only the current state withchildren_signal_vec()
, but it feels like a workaround.How about adding a function that renders a dom node based on a signal, and adds it as a child to a parent node (here's a draft: #18)?
Then it could be used something like this:
Or maybe there are other, better ways to solve this?
The text was updated successfully, but these errors were encountered: