DEV Community

Play Button Pause Button
George K.
George K.

Posted on

Importance of keys when rendering elements in react

Importance of keys in react -- Barcelona Code School

We know that React wants us to use keys for each element rendered in the loop. The reason for that is that once data changes React can identify which element was changed and re-render elements properly.

By default if no keys provided React will use indexes from the array and often we default to using them as well. But we need to remember that it can cause some issues in case of changes in the data.

In this video we can see a simple example of these sort of problems and an easy way to avoid them.

Top comments (0)