Hello everyone,
i need to update the state and load new resources from the server each time the view is changed. I found 'daterangechange' event very useful but there is one small bug. Every time i change the mode to 'month' and back to the 'week' i get unexpected date range (startDate, endDate) which is always in the middle of the current month, regardles of the date.
calendar.current.on('daterangechange', (data: any) => { //data property always returns range from 9.5 - 16.5. when i switch from month to week even it should return the week after (today is 26.5.)
const startDate = moment(data.new.startDate);
const endDate = moment(data.new.endDate);
const diferenceStartEndDate = endDate.diff(startDate, 'days');
const mode =
diferenceStartEndDate < 3 ? 'day' : diferenceStartEndDate >= 3 && diferenceStartEndDate < 10 ? 'week' : 'month';
setCalendarConfig({ //state setter
dateFrom: startDate.toISOString(),
dateTo: endDate.toISOString(),
mode: mode,
});
When i switch between day and week it works as expected every time. Also when state setter is removed it works fine but i don't update my view with new data.
Thank you!