question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning for missing "key" prop

See original GitHub issue

Hello, I tried your library, which is great so far to replace JSX. I have an issue with the “key” property, as soon as I pass more than one component in the array of children, I have the warning that I need to add a “key” prop to each children. I’m pretty sure it’s not needed with JSX when you declare components without explicitly passing an array :

// key prop is added automatically I suppose ?
return (
  <div>
    <Component1 />
    <Component2 />
  </div>
)

So my question is, is it possible to add this key prop automatically ?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
davidpelaezcommented, Apr 21, 2016

We did upgrade, but removing the manual keys attribute shows the warning. Should I have these or not? Here’s for example a render that without the mnaul keys would complain:

render() : React.Element {
    let children = [];
    const groupsElements = this.buildTableGroups();
    children.push(
      div({ key: 'groups', className: styles.groups }, [groupsElements])
    );
    if (this.props.currentBill){
      children.push(
         TableDetail( { key: 'TableDetail', ...this.props.currentBill } )
      );
    }
    return section( { className: styles.board }, [ children ] );
  }
};
1reaction
davidpelaezcommented, Apr 21, 2016

Would anyone mind giving a sample into how to use it properly to avoid the keys warning? We are adding the key manually, but it feel wrong. I was looking through the issues to to see if there was something related and came to this, but unfortunately I cannot figure how to do it without manual keying of elements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint: Missing "key" prop for element in iterator (react/jsx-key)
I am not sure if I did this properly, but I have assigned a unique ID number for each person in the user...
Read more >
react_missing_key_prop - Rule | DeepScan
This rule applies when key prop is missing at each element inside the children of a React element. In React, rendering is optimized...
Read more >
jsx-key `Missing "key" prop for element in array` when there is ...
Hello, I just upgraded eslint-plugin-react from 7.28.0 to 7.29.0 The result is I now get a Missing "key" prop for element in array...
Read more >
Warning: Each Child in a List Should Have a Unique 'key' Prop
Learn what causes"Warning: Each child in a list should have a unique 'key' prop."
Read more >
1336621 - React missing key warnings in Frame and StackTrace
... react-dev.js:22807:9 16:52:21.955 "Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `StackTrace`....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found