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: ''};
  }


To set state

render() {
    return <input onChange={(e) => this.setState({searchTerm: e.target.value})}/>;
  }

Comments

Popular posts from this blog

ES6 / ES2016 Notes

ReactJS Components

NPM