domvm: returning null in a view
Returning null throws errors, is there a way not to return a root node?
render(vm) {
return vm.state.bool ? <div>foo</div> : null;
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (11 by maintainers)
probably the most ergonomic way to achieve a near-equivalent of a
nullreturn is to return a comment node for the view’s root. this means that the view is effectively unmounted and out of the dom, but is still retained by domvm:ah, ok.
i’ll give this some thought. it’s not a quick fix, but i see how it’s useful and better than create & inject, though i do wonder if that can be made into something similar without modifying the core.
i don’t see anything in https://reacttraining.com/react-router/web/example/basic that can’t be replicated with a bit of js and domvm. this “maintaining view state despite unmounting in a declarative way” seems to be the thorny part.
would be interesting to do a proof of concept with createView, injectView and vm memoization to simulate this. it’s certainly possible, though the ergonomics could be anywhere on the scale from not-too-bad to wtf.