How should you conditionally return different child components while maintaining reactivity? #289
kennycarruthers
started this conversation in
General
Replies: 1 comment 1 reply
-
Your first piece of code would just work: const ChildView = (data) => {
if (data.val.errors) {
return div(h1('Errors'), ...)
}
if (data.val.state === 'pending') {
return p('Pending...');
}
return div(...);
} Basically, to make ParentView(() => ChildView(data)) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is the idiomatic way to maintain reactivity and return different child components depending on the
val
of astate
?Imagine the components being returned are bigger such that using a ternary operator somewhere is a bit too unwieldy...
One use case we're exploring is toggling the visibility of form elements based on the state of other form elements. The form is quite complex, so the individual "fieldsets" have been refactored into sub-components.
Beta Was this translation helpful? Give feedback.
All reactions