Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are item keys required when rendering an array in React v15?

Tags:

reactjs

In earlier versions of React, I remember getting a warning when rendering an array without specifying a unique key for every item:

render() {
  return (
    <div>
      {this.props.items.map(item => <span>{item.text}</span>)}
    </div>
  );
}

I understand that it is recommended to specify keys when rendering a dynamic list of items (where items can be added or removed) to help the reconciliation algorithm. I'd like to understand:

  1. Why React doesn't warn anymore when keys are missing?
  2. For static lists, is there a value in specifying item keys?

Official pointers will be appreciated.

like image 518
Misha Moroshko Avatar asked Apr 21 '26 09:04

Misha Moroshko


1 Answers

Actually, I still see this warning message, and in official release notes there is no mention about this case

Example

like image 117
Oleksandr T. Avatar answered Apr 22 '26 21:04

Oleksandr T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!