This is how I declare my state :
const [pickedDates, setPickedDates] = useState(['','']);
This is the callback for the RangePicker's onChange:
const handleDateChange = (dates:any,dateString:any) => {
if(dates){
let startDate = dateString[0];
let endDate = dateString[1];
console.log(startDate);
console.log(endDate);
setPickedDates([startDate,endDate]);
console.log(pickedDates);
}
}
And this is how I have my RangePicker:
<RangePicker onChange={handleDateChange}/>
The issue is that when I pick the start and end date from the RangePicker, the pickedDates state should update and should have the start and end date. But it doesn't, not until the next time I change the dates on the RangePicker, then it has the previous dates instead. Essentially, it is always one step behind. I know this because I printed the pickedDates state in the handleDateChange callback.
Here is an output from the console:
As you can see, the first time when I selected two dates, the pickedDates state is actually empty ['','']. Then I select a new set of dates and now the pickeDates state has the previous dates that I selected. I am not sure what is going on. I'd really appreciate some help!
This is what the RangePicker looks like: