Hello Devs,
In this tutorial, we are going to learn about react textarea onchange event example.
Given below is the example code and the output:
Example Code:
import React, { Component } from 'react';
import { render } from 'react-dom';
class App extends Component {
constructor() {
super();
this.state = {
body: 'This is body'
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({body: event.target.value});
}
handleSubmit(event) {
console.log(this.state);
event.preventDefault();
}
render() {
return (
<div>
<h1>React Textarea onChange Example - Rathorji.in</h1>
<form onSubmit={this.handleSubmit}>
<strong>Body:</strong>
<textarea
value={this.state.body}
onChange={this.handleChange} />
<input type="submit" value="Submit" />
</form>
</div>
);
}
}
render(<App />, document.getElementById('root'));
Output:
{body: "This is body ghgh"} |
I hope this example helps you.