Clear reactJs textarea after submit
so if some one stuck in this problem , I was using uncontrolled component and it is somehow complex to clear it, I just change to controlled one and then got it :)
<form onSubmit={e => this.handleSubmit(e)}>
<textarea value={this.state.text} onChange={ e => this.handleChange(e) } />
<button>Submit Comment</button>
</form>
very important to prevent default
handleSubmit = event => {
event.preventDefault();
this.setState({ text: '' });
};
Basically your form is not getting unmounted. So writing the code in componentDidMount will not make sense. So the quick fix for your problem would be to clear the textarea box after you read the value in handle submit method
handleSubmit: function (event) {
event.preventDefault();
var notes = this.refs.notes;
var details = {
studentId: this.props.studentId,
schoolId: this.props.schoolId,
notes: notes.value
};
notes.value = ""; // Unset the value
this.props.onSubmit(details);
},