lambda - JS

参考《Arrow functions

 Before rewriting:

 handleSubmit = (e) => {
     e.preventDefault();
     this.props.addTodo(this.state.item);
     this.setState({item: ''}, function() {
       this.refs.item.focus();
     });
   }
submit method

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.

猜你喜欢

转载自www.cnblogs.com/xiaobin-hlj80/p/9148569.html