|
|
|
|
|
by chatmasta
3312 days ago
|
|
Is it considered best practice to use the "key" of a child element to signify if it should rerender? This is what I've been doing and it seems to work well. If a parent updates its state, and then as a result, changes the props of some or all of its children, the parent sets the "key" of a child to effectively a hash of the props of that child. |
|
The idea is that this is used to suggest whether when rendering a component, the children are new components, or simply existing components with updated props.
E.g. You have a component that renders a list of items. If you add an item, what you would rather do is create a single new child component and re-use the previously generated children vs. discarding the child components from a the previous render and creating a brand new set.
If you create a key based on a hash of the props this will decrease the time taken to re-render an set of child components with identical props, but at the cost of discarding an existing component and creating a new one if one of the props changes.
Or something like that.....
See for a bit more detail: https://facebook.github.io/react/docs/reconciliation.html