0

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)
}

1 Answer 1

1

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)
}
Sign up to request clarification or add additional context in comments.

2 Comments

I tried printing the values and I get undefined when calling handleSelect
I just ended up passing the id since that it what was needed for the API call. That method just passed an object and I was unable to access the values. I was probably missing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.