ES6 functions, arrow functions and 'this' in an ES6 class [duplicate]
This question already has an answer here: Should I write methods as arrow functions in Angular's class 3 answers Arrow vs classic method in ES6 class 1 answer class App extends Component { constructor(props) { ... } onChange = (e) => this.setState({term: e.target.value}) onSubmit(e){ e.preventDefault(); const api_key = "C1hha1quJAQZf2JUlK"; const url = `http://api.giphy.com/v1/gifs/search?q=${this.state.term}&api_key=${api_key}`; } render() { return ( <div> <form onSubmit={this.onSubmit}> <input value={this.state.term} onChange={this.onChange}/> <button>Search!</button> </form> </div> ); } }