Search code examples
reactjsreduxreact-reduxredux-formreact-datepicker

React Datepicker with redux-form


How to make the react-datepicker bind with 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}  
  />
} />

Whenever i submit the redux form does return an empty object not binding the datepicker's value...

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? 
    })
  }

Solution

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