来自 <select> 字段的反应 onChange 未触发

React onChange from <select> field not firing

我有父组件和子组件。我的子组件包含一个带有一些选项的 select 字段,这些应该在单击 (onChange) 时更新父级的状态,但它们不会。当 onChange() 发生时,我将一个调试器放入函数中,该函数应该是 运行,但它永远不会命中它。我哪里错了?

Parent Component Function

 updateModal(evt) {
  this.setState({ reason: evt.target.value})
 }

像这样作为道具通过:

<PastSessions
  updateModal={this.updateModal.bind(this)}
/>

然后这是我的 Child Component 和 select 字段。

<select value={this.props.reason} onChange={this.props.updateModal}>
   <option value='One'>One</option>
   <option value='Two'>Two</option>
   <option value='Three'>Three</option>
</select>

我最终重写了它并且它有效。看起来像这样:

  handleUpdateChange(e) {
    this.setState({
      reason: e.target.value
    })
  }

像这样作为道具通过

handleUpdateChange={this.handleUpdateChange.bind(this)}

这样称呼

<select value={this.props.reason} onChange={this.props.handleUpdateChange}>

很有魅力