Skip to content

Each child in an array does not need a unique key #8920

Closed
@neaumusic

Description

@neaumusic

Note the keys 'react-is' and 'very-stupid'

const welcomeUser = this.state.existingCookie.username && [
  <div className={CSS.welcomeUser} key='react-is'>
    {i18n.t('Welcome ') + this.state.existingCookie.username}</div>,
  <div className={CSS.pleaseLogIn} key='very-stupid'>
    {i18n.t('Please log in')}</div>
];

return (
  <div className={CSS.sky}>
    {welcomeUser}</div>
);

Do you want to request a feature or report a bug?
No

What is the current behavior?
Cannot pass around array of JSX without unnecessary keys

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).

What is the expected behavior?
React shouldn't care if I put keys on my own elements, and should not console.warn

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Latest

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