What is the impact of indexes as keys in react.js?

Answer

Keys should be stable, predictable, and unique so that React can keep track of elements.
This limits the optimizations that React can do.

{todos.map((todo, index) =>
<Todo
{...todo}
key={index}
/>
)}
If you use element data for unique key, assuming todo.id is unique to this list and stable, React would be able to reorder elements without needing to reevaluate them as much.

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

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---