srigar / multiselect-react-dropdown

React multiselect dropdown with search and various options
https://10xn41w767.codesandbox.io/
MIT License
200 stars 114 forks source link

Each child in a list should have a unique "key" prop #30

Closed hsaleem11 closed 4 years ago

hsaleem11 commented 4 years ago

Hello, I get this warning when using this library:

Warning: Each child in a list should have a unique "key" prop

I added a unique key to each item I'm rendering in the dropdown, but this warning doesn’t go away. I also followed the examples you have, but this issue is still there. Are you providing a unique key for each item in the dropdown list in the source code?

srigar commented 4 years ago

@hsaleem11 All places key attr are there. Can u please share ur options JSON structure?

hsaleem11 commented 4 years ago

Hello @srigar

Here is an example of the JSON structure I am using:

{id: 0, value: "testValue", groupName: "testGroupName"}

The id's are unique for all options in my list. I also tried adding a "key" property to my JSON structure, but it still shows the same error. Also, I am populating the dropdown list inside the "componentDidMount()" function. Is my JSON structure correct, or am I using this wrong?

queenielyk commented 4 years ago

I am facing the same problem also. I found this problem will only exist if using parameter 'groupBy'

hsaleem11 commented 4 years ago

Yes, if I remove the 'groupBy' parameter the error doesn’t show up anymore. However, I still need the items to be grouped. Does anyone know how to resolve this issue?

jmsaucier commented 4 years ago

https://github.com/srigar/multiselect-react-dropdown/blob/434b615e20d53ef6943280b6d5ff84f94c18023d/src/multiselect/multiselect.component.js#L303

needs a key prop passed to it. @srigar , I can open a PR for this if you would like.
jmsaucier commented 4 years ago

Went ahead and opened the PR since the change was small.

https://github.com/srigar/multiselect-react-dropdown/pull/32

hsaleem11 commented 4 years ago

Thanks for looking into this @jmsaucier, it looks like this should fix the issue. @srigar can you review and merge this PR?

srigar commented 4 years ago

Changes are available in @1.4.8