Understanding unique keys for array children in React.js

后端 未结 12 1299
时光取名叫无心
时光取名叫无心 2020-11-21 05:45

I\'m building a React component that accepts a JSON data source and creates a sortable table.
Each of the dynamic data rows has a unique key assigned to it but I\'m stil

12条回答
  •  感情败类
    2020-11-21 06:21

    This is a warning, But addressing this will make Reacts rendering much FASTER,

    This is because React needs to uniquely identify each items in the list. Lets say if the state of an element of that list changes in Reacts Virtual DOM then React needs to figure out which element got changed and where in the DOM it needs to change so that browser DOM will be in sync with the Reacts Virtual DOM.

    As a solution just introduce a key attribute to each li tag. This key should be a unique value to each element.

提交回复
热议问题