How do I pass multiple parameters to an event handler in a React component?
-
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 -
//функция
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
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!