Reputation: 379
I want to execute a additional function in ReactJS onChange in input type text field, then render function is:
render(){
return (
<div>
<InputText />
</div>
)
}
The InputText component is:
class InputText extends React.Component {
onChange(e){
console.log("you typed again...");
}
render() {
return (
<input type="text" placeholder="search..." onChange={this.onChange()} />
);
}
}
The console log is to execute while user is typing but with my method the console log comes only if page is loaded.
What I have to fix there to get it runing if user start with typing?
Upvotes: 0
Views: 452
Reputation: 62763
Instead of calling the function within the onChange
prop, like:
onChange={this.onChange()}
you only need to pass the function, like:
onChange={this.onChange}
Upvotes: 1