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 not working inside Array.map()

See original GitHub issue

Exact same component is working outside the loop but not working inside the Array.map function, as required to loop through a list of drop-down array.

  • components: Dropdown
  • reactstrap version #5.0.0-beta
  • import method es
  • react version #16.2.0
  • bootstrap version #4.0.0

What is happening?

I have a array of data that generates a new dropdown via looping but the dropdown is not working inside the loop but if I cut paste the code snippet outside the loop the dropdown stops working. It Displays the button but nothing happens when clicked.

What should be happening?

It should display the other options in the dropdown list.

Error message in console

No Error in Console. 

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TheSharpieOnecommented, Mar 7, 2018

UncontrolledDropdown works the same way as Dropdown you just don’t provide the isOpen and toggle props. If you need either one of those (to gain more control), you’ll have to use Dropdown directly. Dropdowns don’t really “change”, they are not like <select>, they don’t have a value. They are primarily for displaying lists of links and such as noted by bootstrap:

Dropdowns are toggleable, contextual overlays for displaying lists of links and more

Because of that, there is no nice way to determine which item was selected. (the same goes for bootstrap.js itself) If you need to determine which item was selected to take action, you can add individual event listeners on the items to determine which one is being clicked. Or Dropdown’s toggle callback should be passed the event which triggered it, which you can use to determine which item was selected (if any) to trigger the toggle (it’s more advanced)

0reactions
Samrat-Saha-Sammycommented, Mar 8, 2018

@TheSharpieOne Thanks for the Prompt response. I think Dropdown should have a onChange callback with the id of the selected option. It a more realistic scenarios to implement a dropdown.

It The addon callback will really help a lot other writing a lot of code in developer side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dropdown menu not showing when mapping through array ...
I am working on a Laravel project that implements ReactJS on the front end and I'm trying to create a drop down menu...
Read more >
How to Convert react-dropdown-select's Default Value from ...
The snippet above helps us place the value key into an entirely new array since that is what we need, and this is...
Read more >
Customize a reusable React dropdown menu component
In the code above, when populating the location array, we have a unique id to use with a key prop of map method....
Read more >
How to Create a Dropdown List with Array Values using ...
Here we will populate the dropdown list with an array. Below is the description of popular approaches used in JavaScript. Example 1: In...
Read more >
Controls | Maps JavaScript API - Google Developers
The Map Type control is available in a dropdown or horizontal button bar style, ... Some controls appear on the map by default...
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