---
title: "Discussion on \"Why React Keys Matter: An Introduction\" | Hashnode"
description: "Discussion on \"Why React Keys Matter: An Introduction\". When working with any type of list in React, you will often encounter this warning if you forgot to include a key prop:\nWarning: Each child in a list should have a unique “key” prop\n\nSo, why does React tell you to include keys and why is it important..."
url: "https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why React Keys Matter: An Introduction](https://blog.lo-victoria.com/why-react-keys-matter-an-introduction?utm_source=hashnode&utm_medium=feed)

When working with any type of list in React, you will often encounter this warning if you forgot to include a key prop: Warning: Each child in a list should have a unique “key” prop So, why does React tell you to include keys and why is it important...

Sep 15, 2020 · 4 min read · blog.lo-victoria.com  
Updated Jul 22, 2024  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#tutorial](https://hashnode.com/tag/tutorial)

## Written by

[Victoria Lo](https://hashnode.com/@victoria)

@victoria · Singapore

  
[View profile](https://hashnode.com/@victoria)

A nerd in books, tea, games and software.

I'm a solutions engineer lead, GitHub Star, Director of WomenDevsSG, and co founder of ragTech. I work at the intersection of tech, systems, and leadership, and this blog is where I share my journey through all three. Expect honest reflections, real experiences, and thoughts that are still forming rather than polished career advice.

## Responses 6

Markdown supported · ⌘↵ to post

[Linus Närkling](https://hashnode.com/@Vapid)

[Sep 23, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f6ae76f1c935b2e4c616628)

Is the "key" attribute special or does React look for any attribute? I have a list of divs where the "title" attribute uniquely identifies the object - will that work just as well?

[LookRain](https://hashnode.com/@lookrain)

[Sep 16, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f6183d5dc74720d9b85e68a)

Excellent writeup on the importance of `key` in React. However, are you sure the diffing is done on the virtual DOM and real DOM? To my understanding, the reconciliation happens between the most recent virtual DOM tree and the previous tree.

[Victoria Lo](https://hashnode.com/@victoria)

[Sep 16, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f6183d5dc74720d9b85e68a#reply-5f618c62dc74720d9b85e6c8)

Thank you for the correction. You are right, I meant to write that diffing is done between the old and virtual DOM in order to then update the real DOM. Sorry for the confusion.

[Bolaji Ayodeji](https://hashnode.com/@bolajiayodeji)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f6108d07317080b4cf5c698)

Well explained [Victoria Lo](https://hashnode.com/@victoria), thanks for sharing!

[Victoria Lo](https://hashnode.com/@victoria)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f6108d07317080b4cf5c698#reply-5f610e55dc74720d9b85e442)

Always a pleasure :)

[Hardik Joshi](https://hashnode.com/@hardik_joshi28)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f60e09ac417c20b18b7217f)

So true! Recently I had a requirement to refresh a component, I initially thought of creating a state variable and refresh it based on that but adding a key solved the issue. I was looking for an article to explain "behind the scenes" and I landed here... Thank you so much for explaining! :)

[Victoria Lo](https://hashnode.com/@victoria)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f60e09ac417c20b18b7217f#reply-5f60fbe17317080b4cf5c5d6)

No problem! Glad it helped :)

[Chris Short](https://hashnode.com/@devcshort)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f60de2e7317080b4cf5c4ba)

Great article!

[Victoria Lo](https://hashnode.com/@victoria)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f60de2e7317080b4cf5c4ba#reply-5f60dfcdc417c20b18b72174)

Thanks! Glad you like it :)

[Dinys Monvoisin](https://hashnode.com/@dinmon)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f608abc64c1f006b49e00c4)

Interesting. I did not know about that. I never came across that.

So from what I understand, react does not re-render the input field when using index. That's why there is this issue. Am I right?

[Victoria Lo](https://hashnode.com/@victoria)

[Sep 15, 2020](https://hashnode.com/posts/why-react-keys-matter-an-introduction/5f603c311d6093023c713314/comment/5f608abc64c1f006b49e00c4#reply-5f60d4197317080b4cf5c427)

In React, components will automatically re-render if there are state changes. In this case, the input field does not re-render because there is no change in its value.

And because its key is mapped to the index instead of id, the position of the input field does not change with its corresponding list item.
