"Warning: u: `key` is not a prop" in console.
See original GitHub issueGreat tree view component, very powerful and easy to use. Thank you for releasing it!
I just implemented it and followed the data structure as per the documentation. In my console react is throwing an error:
Warning: u: key
is not a prop. Trying to access it will result in undefined
being returned. If you need to access the same value within the child component, you should pass it as a different prop.
Is this something that I can fix or will it require a update to the component code?
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Warning: `key` is not a prop - Stack Overflow
Everything works for me but in the console I get a warning: When I click on a note, I transfer the data to...
Read more >Key is not a prop. Trying to access it will result in `undefined`
The warning " key is not a prop. Trying to access it will result in undefined being returned" is caused when we try...
Read more >How to resolve React console warnings about unique `key ...
Warning: Fr: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the...
Read more >Warning: Each Child in a List Should Have a Unique 'key' Prop
When creating a list in the UI from an array with JSX, you should add a key prop to each child and to...
Read more >Everything you need to know about the key prop in React
Software Engineer Not responding… ... Well, we now see the list of our items, but what is this warning in our console? ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, sorry my bad.
My example code above isn’t correct. In order to prevent all the warnings of such kind. You need a custom component to explicitly consumes the props instead of using native elements like li.
You can check how I implement it here.
Still getting error --> Warning: u:
key
is not a prop. Trying to access it will result inundefined
being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)Code–>
const treeData = [ { key: “first-level-node-1”, id: “first-level-node-1”, label: “Node 1 at the first level”, nodes: [ { key: “second-level-node-1”, id: “second-level-node-1”, label: “Node 1 at the second level”, nodes: [ { key: “third-level-node-1”, id: “third-level-node-1”, label: “Last node of the branch”, nodes: [] // you can remove the nodes property or leave it as an empty array } ] } ] }, { key: “first-level-node-2”, id: “first-level-node-2”, label: “Node 2 at the first level” } ];
<TreeMenu hasSearch={true} data={treeData} onClickItem={node => { //this.handleTreeClick(node); }} > {({ search, items }) => (
{items.map(({ key, …props }) => ( <ItemComponent {…props} key={props.id} /> ))}
)} </TreeMenu>Please help!