用redux-form反应Datepicker

用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} />