You get a bonus - 1 coin for daily activity. Now you have 1 coin

What is the impact of using indexes as keys? in REACT

Practice



Keys should be stable, predictable and unique so that React can keep track of elements.

In the code snippet below, each element's key will be based on ordering, rather than tied to the data being represented. This limits the optimisations that React can perform.

{todos.map((todo, index) =>
  <Todo
    {...todo}
    key={index}
  />
)}

If you use the element data for a unique key, assuming that todo.id is unique to this list and stable, React will be able to reorder elements without needing to re-evaluate them.

{todos.map((todo) =>
  <Todo {...todo}
    key={todo.id} />
)}

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone