参考《Arrow functions》
Before rewriting:
handleSubmit = (e) => { e.preventDefault(); this.props.addTodo(this.state.item); this.setState({item: ''}, function() { this.refs.item.focus(); }); }
After rewriting:
handleSubmit = (e) => { e.preventDefault(); this.props.addTodo(this.state.item); this.setState( {item: ''}, this.focus_input() ); }
arrow function:
focus_input = () => { this.refs.item.focus(); }
The code on the Github.