Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call 2 functions within onChange event

I'm a bit stuck with my component, I need to call onChange from props so

<input type="text" value={this.state.text} onChange={this.props.onChange} /> 

but also call another function within the component called handleChange() that updates the state.text, I tried

 <input type="text" value={this.state.text} onChange={this.props.onChange; this.handleChange} /> 

but this doesn't seem to work.

like image 661
Ilja Avatar asked Feb 16 '16 14:02

Ilja


People also ask

How do you call two functions on onChange event?

Create a function, call it on change event and inside that, call 2(or you can even call 20) functions.

Can we call multiple function on onChange?

Can i call two functions onchange()? You can also call one function, and two (or more) others from that.

How do I call multiple functions in JavaScript?

Given multiple functions, the task is to call them by just one onclick event using JavaScript. Here are few methods discussed. Either we can call them by mentioning their names with element where onclick event occurs or first call a single function and all the other functions are called inside that function.

Can you have two onClick events React?

The first solution to perform multiple onClick events in React is to include all of your actions inside of a function and then call that single function from the onClick event handler. Let's explore how to do that in a React Component: import React from 'react'; function App() { function greeting() { console.


1 Answers

You can do it by putting the two functions in double quotes:

<input type="text" value={this.state.text} onChange="this.props.onChange(); this.handleChange();" /> 

This should work. But it would be better if you call the second function within the first one:

function testFunction() {     onChange();     handleChange(); } 
like image 189
diiN__________ Avatar answered Oct 03 '22 18:10

diiN__________