Raja Muhammad Asher
Raja Muhammad Asher

Raja Muhammad Asher

What are keys in React?

Photo by Lautaro Andreani on Unsplash

What are keys in React?

Raja Muhammad Asher's photo
Raja Muhammad Asher
·Aug 5, 2022·

1 min read

Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity:

const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
  <li key={number.toString()}>
    {number}
  </li>
);
 
Share this