Reputation: 285
I have a dropdown button with the eventhandler:
onSelect={this.handleSelect.bind(this)}>
However the first param i receive is undefined the second param is Proxy with info about the event. Why is my first param undefined?
private handleSelect(e1, e2) {
debugger;
e1;
console.log(e2);
}
e1 is undefined e2 holds event details
the event handler is called on select which resides in an arrow function
renderRanks = () => {
const { intl } = this.props;
return (
<DropdownButton bsSize="sm" id="ranks"
title={"Title"}>
{this.store.levels.map((pl) =>
<MenuItem data={pl.Id} key={pl.Number}>{pl.Name}</MenuItem>)}
</DropdownButton>
)
}
Which is being called from my render
{this.renderDropdown()}
Upvotes: 1
Views: 160
Reputation: 2639
onSelect
event handler expects eventKey and event as its params. You are declaring key
(from react) but you aren't declaring eventKey
(from react-bootstrap).
<MenuItem data={pl.Id} key={pl.Number} eventKey={pl.Number}>{pl.Name}</MenuItem>)}
editing your MenuItem
populate call as above should then give you e1
-> eventKey and e2
-> event in your handleSelect
Upvotes: 1
Reputation: 351
Use onChange event instead. your function handleSelect will be like below
handleSelect = (event) => {
const e1 = event.target.value // contains value of select
const e2 = event // contains event object
}
Upvotes: 1