haoxins / react-flatpickr

flatpickr for React
MIT License
598 stars 102 forks source link

Fixed usage example in Readme.md #164

Closed janpaepke closed 3 years ago

janpaepke commented 3 years ago

The onChange callback actually passes an array of selected dates, not a single one. So to set the new state to the selected date, one has to only use the first element of the passed in value.

The current suggestion (desctructuring the parameter) is the one with the least changes, but may be difficult to understand for inexperienced users. A more verbose but potentially more comprehensive way of writing this could be:

onChange={selectedDates => {
    this.setState({ date: selectedDates[0] });
}}