Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>However, I've never seen it documented what actual process is used to determine the identity of a calling component.

The first caller gets the first state, the second caller gets the second state, etc.



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.


By 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


It'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: