我有父和子組件。我的子組件包含一個帶有一些選項的選擇字段,這些應該在點擊時更新父項的狀態(onChange),但它們不會。我把一個調試器投入到應該在onChange()
發生時應該運行的函數中,但它從來沒有碰到它。我在哪裏錯了?反應onChange從<select>字段不發射
Parent Component Function
updateModal(evt) {
this.setState({ reason: evt.target.value})
}
傳遞的道具,像這樣:
<PastSessions
updateModal={this.updateModal.bind(this)}
/>
然後這裏是我Child Component
與選擇欄。
<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>
包裝this.props.updateModal在你的孩子部分與另一個福 – Sri