Skip to content

Don't quite see using index as key has problems? #2752

Description

@KennethKinLum

On page https://reactjs.org/docs/reconciliation.html
it is said that

Here is an example of the issues that can be caused by using indexes as keys on CodePen

How can the issue be created? I added record to the front, to the back, and sort them, and they seemed to work ok?

Actually, here is a simple case and I can't break it: https://stackoverflow.com/questions/60283967/in-reactjs-using-array-index-as-key-is-said-to-not-work-well-but-i-cant-make

I can only break it if it is all 3 conditions:
It has to be function component using useState, and I have to mutate the state (which the docs says I shouldn't do), and use index as key. So if I don't mutate the state, I can't make it not work well if I use index as key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions