I am using React-Bootstrap. The onSelect trigger for dropdowns were not allowing me to pass data. Just the event. So remember you can just set any values as attributes and pick them up from the function using javascript. Picking up those attributes you set in that event target.

    let currentTarget =;
    let currentId = currentTarget.getAttribute('data-id');
    let currentValue = currentTarget.getAttribute('data-value');


I use the following code:

<Button onClick={this.onSubmit} id={item.key} value={shop.ethereum}>

Then inside the method:

onSubmit = async event => {
    console.log("Param passed => Eth addrs: ",
    console.log("Param passed => id: ",

As a result:

Param passed in event => Eth addrs: 0x4D86c35fdC080Ce449E89C6BC058E6cc4a4D49A6

Param passed in event => id: Mlz4OTBSwcgPLBzVZ7BQbwVjGip1


in function component, this works great - a new React user since 2020 :)

handleRemove = (e, id) => {

return(<button onClick={(e)=> handleRemove(e, id)}></button> )



Don't bind function (nor use arrow functions) inside render method. See official recommendations.

So, there's an accepted answer and a couple more that points the same. And also there are some comments preventing people from using bind within the render method, and also avoiding arrow functions there for the same reason (those functions will be created once again and again on each render). But there's no example, so I'm writing one.

Basically, you have to bind your functions in the constructor.

class Actions extends Component {

    static propTypes = {
        entity_id: PropTypes.number,
        contact_id: PropTypes.number,
        onReplace: PropTypes.func.isRequired,
        onTransfer: PropTypes.func.isRequired

    constructor() {
        this.onReplace = this.onReplace.bind(this);
        this.onTransfer = this.onTransfer.bind(this);

    onReplace() {
        this.props.onReplace(this.props.entity_id, this.props.contact_id);

    onTransfer() {
        this.props.onTransfer(this.props.entity_id, this.props.contact_id);

    render() {
        return (
            <div className="actions">
                <button className="btn btn-circle btn-icon-only btn-default"
                        <i className="fa fa-refresh"></i>
                <button className="btn btn-circle btn-icon-only btn-default"
                    <i className="fa fa-share"></i>

export default Actions

Key lines are:


this.onReplace = this.onReplace.bind(this);


onReplace() {
    this.props.onReplace(this.props.entity_id, this.props.contact_id);




Something nobody has mentioned so far is to make handleRemove return a function.

You can do something like:

handleRemove = id => event => {
  // Do stuff with id and event

// render...
  return <button onClick={this.handleRemove(id)} />

However all of these solutions have the downside of creating a new function on each render. Better to create a new component for Button which gets passed the id and the handleRemove separately.


onClick={this.handleRemove.bind(this, id)}

Using with arrow function



Use Arrow function like this:

<button onClick={()=>{this.handleRemove(id)}}></button>


Use the value attribute of the button element to pass the id, as

<button onClick={this.handleRemove} value={id}>Remove</button>

and then in handleRemove, read the value from event as:

handleRemove(event) {

This way you avoid creating a new function (when compared to using an arrow function) every time this component is re-rendered.


Remember that in onClick={ ... }, the ... is a JavaScript expression. So

... onClick={this.handleRemove(id)}

is the same as

var val = this.handleRemove(id);
... onClick={val}

In other words, you call this.handleRemove(id) immediately, and pass that value to onClick, which isn't what you want.

Instead, you want to create a new function with one of the arguments already prefilled; essentially, you want the following:

var newFn = function() {
  var args =;

  // args[0] contains the event object
  this.handleRemove.apply(this, [id].concat(args));
... onClick={newFn}

There is a way to express this in ES5 JavaScript: Function.prototype.bind.

... onClick={this.handleRemove.bind(this, id)}

If you use React.createClass, React automatically binds this for you on instance methods, and it may complain unless you change it to this.handleRemove.bind(null, id).

You can also simply define the function inline; this is made shorter with arrow functions if your environment or transpiler supports them:

... onClick={() => this.handleRemove(id)}

If you need access to the event, you can just pass it along:

... onClick={(evt) => this.handleRemove(id, evt)}

Related Query

More Query from same tag