React State
Each class has a state
Each instance of a class has its own copy of state object
A state always needs to be initialised like so:
constructor(props) {
super (props);
this.state = {searchTerm: ''};
}
Each instance of a class has its own copy of state object
A state always needs to be initialised like so:
constructor(props) {
super (props);
this.state = {searchTerm: ''};
}
To set state
render() {
return <input onChange={(e) => this.setState({searchTerm: e.target.value})}/>;
}
Comments
Post a Comment