Reputation: 21
I have a dropdown list from an array of values like mapped to a dropdown and a handleSelect
const handleSelect = (e) => {
handleShow()
setCommunityName(e)
}
<DropdownButton id="dropdown-basic-button" title="Join Community" onSelect={handleSelect} hidden={showJoin}>
{communities.map(data =>
<Dropdown.Item title={data.CommunityName} key={data.id}
eventKey={data.CommunityName}>{data.CommunityName}</Dropdown.Item>)}
</DropdownButton>
Right now only data.CommunityName is set in state, but I would also like to set the state of data.id as well. I was trying to do something like this?
const handleSelect = (e, i) => {
handleShow()
setCommunityName(e)
setCommunityId(i)
}
Upvotes: 0
Views: 47
Reputation:
What about setting the entire object as value?
<Dropdown.Item title={data.CommunityName} key={data.id}
eventKey={data}>{data.CommunityName}</Dropdown.Item>)}
const handleSelect = (e) => {
handleShow()
setCommunityName(e.CommunityName)
setCommunityId(e.id)
}
Upvotes: 1