How do I pass multiple parameters to an event handler in a React component?

  • 0
    How do I pass multiple parameters to an event handler in a React component? I tried the option
    <input onInput={this.handleEvent.bind(this, "SOME TEXT", 0)} />

    and option
    <input onInput={this.handleEvent.bind("SOME TEXT", 0)} />

    This does not work. The handler function itself can be, for example, like this:
    handleEvent = (theEvent, theText, theNumber) => {
        alert(theEvent.target.value);
        alert(theText);
        alert(theNumber);
    }
    JavaScript Anonymous, Sep 24, 2019

  • 1 Answers
  • 0
    //функция
    handleEvent= (arg1, arg2, arg3) => (e) => {
    console.log(e.target.value); //значение инпута, если надо
    console.log(arg1); //аргумент 1
    console.log(arg2); //аргумент 2
    console.log(arg3); //аргумент 3
    }

    //вызов
    <input onInput={this.handleEvent(arg1, arg2, arg3)}/>
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!