You are mapping over the elements, the map method gives you the indices of the element, you could bubble the index of the given selected element via handler using the onClick prop
{props.dropDownItems.map((element, index) => (
<MenuItem key={element + index} value={element} onClick={()=> handleItemClick(index)} >
{element}
</MenuItem>
))}
The handleItemClick code will be as in the following
const handleItemClick = (idx) => {
console.log(idx);
}
* Be the first to Make Comment