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.

Dropdown's options can cause key warnings

See original GitHub issue

Line 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:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
levithomasoncommented, Feb 3, 2017

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.

0reactions
levithomasoncommented, Apr 27, 2018

@TallOrderDev this issue from Jan 2017 and the Dropdown no longer includes a hidden select with option elements. Those old option elements are what used to use the key via the value.

If you have multiple items with the same value, you should explicitly set a key on those options. If you do not supply a key, we are forced to use something so we use the value.

Best!

Read more comments on GitHub >

github_iconTop 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 >

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