Dropdown's options can cause key warnings
See original GitHub issueLine 999 in Dropdown.js currently reads:
<option key={option.value} value={option.value}>{option.text}</option>`
This causes problems when two options in the dropdown have the same value since you assign the key manually. Please either do not manually assign a key or do what it does for Dropdown.Item:
<DropdownItem
key={`${opt.value}-${i}`}
/>
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Dropdown: items missing "key" prop, React warning displayed
Keys in Dropdown options are still required and still work. If you do not pass a key we will use the value as...
Read more >Excel Data Validation Tips and Troubleshooting - Contextures
The videos and written steps below will help you with data validation drop down list troubleshooting in Microsoft Excel.
Read more >Dropdowns - Bootstrap
Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They're made interactive with the included Bootstrap dropdown ...
Read more >Getting key prop warning in React, even though key is set
My understanding of that has always been that if you are iterating over component that generates HTML, the key should be on the...
Read more >The Ultimate Guide to Dropdown Lists in Excel
Make sure the Show error alert after invalid data is entered option is checked. It should be enabled by default. Select the Style...
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
You must use a string/number as the value. There are several reasons for this internal to the component. I’m currently updating the Dropdown to allow shorthand
options
, #1038, which explored the idea of allowing shorthand values, like objects. It was decided against due to complexity and it is not simple for users.I, unfortunately, cannot detail all the reasons ATM due to time constraints. You should use a string/number value and lookup the object in your data array with methods outside of the dropdown.
@TallOrderDev this issue from Jan 2017 and the Dropdown no longer includes a hidden
select
withoption
elements. Those oldoption
elements are what used to use the key via thevalue
.If you have multiple items with the same value, you should explicitly set a
key
on those options. If you do not supply akey
, we are forced to use something so we use thevalue
.Best!