4 ms·
Clearly, there has to be more to it than that. Whole subtrees of the virtual DOM can (in some circumstances) be removed without affecting the states of the sub
by recursive 4y ago
Clearly, there has to be more to it than that. Whole subtrees of the virtual DOM can (in some circumstances) be removed without affecting the states of the subsequent components. I'm not totally sure what the rules are for this, but at least sometimes it works.
- unconed 4y agoIt's not some big mystery and it's documented just fine. If you have a normal chunk of static jsx, child "i" maps to slot "i". If you wish to omit a child dynamically, you put a null in its place. If you have an array of children being built dynamically, every child needs an explicit key. This avoids state being shifted up and down needlessly when you add/remove. You will never get another component's state back because changing the type forces a remount. Unlike React, Live has the ability to preserve children even if the parent type changes (a morph), but this is opt-in only and will still discard the state of the parent.
- pygy_ 4y agoBy default, identity is the place in the vDOM tree (taking `null` nodes into account so that you can have conditional nodes in fragments/children lists). In lists, identity can instead be tracked by a user-provided key: https://reactjs.org/docs/lists-and-keys.html https://reactjs.org/docs/lists-and-keys.html