Our powerful JS Calendar component


Post by djordjijem »

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!


Post by Maxim Gorkovsky »

Hello.
I am not sure I understand the problem here.

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.

This suggests problem is with your code which is trying to set new start/end dates. Have you tried logging them?

If you could provide runnable test case, we would take a look at it.

Also to check current mode you can refer to the calendar.mode, no need to calculate anything.


Post Reply