我有一個多表單組件的子步驟。在其中一個組件上,我試圖實現YouCanBookMe DatePicker。React Datepicker輸入狀態不變?
現在,當我嘗試更新datepicker值的狀態,就像我對其他常規文本輸入所做的那樣,狀態不會更新。如果我輸入日期,狀態會得到更新,但當我實際從選取器中選擇日期時不會。我真的無能爲力。你們能否指出爲什麼它沒有?
非常感謝您的幫助。我是React的新手,我嘗試了3個不同的Datepicker庫,並且我慢慢地瘋了,因爲沒有人能夠工作,或者我無法將其轉換爲父子結構。謝謝!
家長:
constructor(props) {
super(props);
this.state = {
wants_interview_date: moment().format("DD-MM-YYYY")
\t }
}
handleChange(field) {
return (evt) => this.setState({ [field]: evt.target.value });
}
render(){
return <FormStep8
wants_interview_date={this.state.wants_interview_date}
onDateChange={this.handleChange('wants_interview_date')} />;
}
子組件:
render() {
<Datetime
timeFormat={false}
dateFormat="DD-MM-YYYY"
inputProps={{id: 'wants_interview_date', onBlur: this.props.onDateChange, value: this.props.wants_interview_date}} //To get the regular HTML input props
/>
}
你從哪裏得到'evt'? –
@MuratK。我不。我不完全理解StateChange方法,但它適用於普通的文本輸入。我從[本教程]中獲得了它(https://goshakkk.name/wizard-form-collect-info/) – Doge