Hey guys i wanna ask a question. So i’m watching a tutorial on react and i have the following code, the thing is i dont understand why why we have to update the “value” of the input with basically the value that it already has xD I placed a comment in the code to help you understand which line im talking about. I mean, why do we have to do that? I hope my question is clear
class SearchBar extends React.Component {
state = { term: '' };
render() {
return (
<div className="ui segment">
<form className="ui form">
<div className="field">
<label>Image Search</label>
<input
type="text"
//check the line bellow
value={this.state.term}
onChange={e =>
this.setState({ term: e.target.value})
} />
</div>
</form>
</div>
);
}
}