用redux-form反应Datepicker [英] React Datepicker with redux-form
本文介绍了用redux-form反应Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使react-datepicker与redux形式绑定?
How to make the react-datepicker bind with redux-form?
我有这个redux-form字段:
I have this redux-form field:
<Field name="due_date" component={props =>
<DatePicker
{...props}
readOnly={true}
selected={this.state.due_date}
value={this.state.due_date}
onChange={this.handleDueDate}
/>
} />
每当我提交redux表单时,都会返回一个空对象,不绑定日期选择器的值...
Whenever i submit the redux form does return an empty object not binding the datepicker's value...
我的onChange:
my onChange :
handleDueDate(date) {
this.setState({
due_date: moment(date).format('L')
}, () => {
// do I need to dispatch and action here to update the redux-form in state tree?
})
}
推荐答案
For future readers, just go to this link: DatePicker in Redux Form
首先,我在上面的链接中创建了类似提及的组件,并在其中传递了选定的道具.就我而言:
first, I created the component like metioned in link above and just passed the selected prop in it. in my case:
<Field
name="due_date"
component={DatePickerComponent}
selected={this.state.date_of_briefing} />
这篇关于用redux-form反应Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文