I'm using react-datepicker
to building my application.
Follow my source code here: https://codesandbox.io/s/xr76olj70o
I wanna get an object with startDate
and endDate
when I choose a specified day like this: {startDate: "24-07-2018", endDate: "31-07-2018"}
My handleSelected
function like this:
handleRangeSelected = () => {
const { startDate, endDate } = this.state;
const range = {
startDate: moment(startDate).format("DD-MM-YYYY"),
endDate: moment(endDate).format("DD-MM-YYYY"),
}
console.log('Range selected!', range);
}
My problem is when I choose a day. At the first time, state
seem isn's update immediately when I pick a day.
Results:
First time: I chose 31/07/2018, it logs result:
Range selected! {startDate: "24-07-2018", endDate: "24-07-2018"}
Second time: I chose 01/08/2018, it logs result:
Range selected! {startDate: "24-07-2018", endDate: "31-07-2018"}
What did I wrong here? Need your help! thanks.