About key values

It is a key attribute, key to the use of REACT identification component, which is a sign of the identity. In general, we use the id data as a key element; but when there is no id element, the element can be used as an index index key. But generally not recommended to use the index as a key value, this will result in poor performance, it may also cause problems in the state assembly.

With key value, you can decide whether to destroy or updated based on key.

  • the same key, if the property of the component is changed, only the update component REACT corresponding attribute, no change is not updated
  • key is not the same, react to the destruction of the component, and then re-create the component

key elements only in the context of an array of nearby makes sense

Why only element in the array needs to have a unique key, while other elements do not need it? The answer is: react ability to identify, update the correspondence between the front and rear elements.

To clear internal logic components, you should have any complex key attributes using the state assembly, in order to have a healthy life cycle suitable for the destruction and reconstruction of the trigger assembly, components.

Guess you like

Origin www.cnblogs.com/tianHHH/p/11001735.html