首页 > 解决方案 > 未捕获的类型错误:this.props.onUpdateUser

问题描述

我收到 Uncaught TypeError: this.props.onUpdateUser is not a function error。我在构造函数中也完成了绑定。但是为什么当我在文本框中写任何东西时它总是抛出同样的错误。

 class App extends Component {
      constructor(props){
        super(props);
        this.onUpdateUser = this.onUpdateUser.bind(this);
      }


    onUpdateUser(event){
      this.props.onUpdateUser(event.target.value);
    }

      render() {
        console.log(this.props);
        return (
          <div className="App">
            <header className="App-header">
              <img src={logo} className="App-logo" alt="logo" />
              <p>
                Edit <code>src/App.js</code> and save to reload.
              </p>

              <input onChange={this.onUpdateUser}/>
              {this.props.user}
            </header>
          </div>
        );
      }
    }

标签: reactjs

解决方案


推荐阅读