Switching between views

Hi. I’m using Mobiscroll 5.19.2 (react), and when I switch from weekly view to monthly view then back to weekly view, I get this console error:

Uncaught TypeError: Cannot read properties of undefined (reading 'date')
        at t._scrollToTime (mobiscroll.react.min.js:2:1)
        at mobiscroll.react.min.js:2:1

This results in me seeing the week before the one I was on before I had changed to the monthly view. The views are in a state variable and it does work. These are my views:

	const views: Views = {
		month: { timeline: { type: 'month', eventList: true, resolution: 'day' } },
		week: {
			timeline: {
				type: 'week',
				startDay: 1,
				endDay: 0,
				resolution: 'day',
				eventList: true,

I’m not setting a defaultSelectedDate or a selectedDate option. I’m letting the calendar decide based on the events I load into it. I load the events using the onPageLoading option where I put the events array into a state variable.

I re-fetch events from the server each time the date is changed in the header controls, or whenever the view is changed.

Please can I ask if there’s something I am doing wrong or missing?

(I should also say that if I don’t load any events or just keep the events array empty, then this error does not occur)

Hello @Sebastien_Pedley :wave:

As my colleague mentioned yesterday, this issue was already fixed in 5.26.2 version:

  • We fixed an issue with the navigate method which was throwing an error when trying to navigate to hidden dates on a week view.

Yes works great now, thank you.

I have a remaining question which is when going back from month view to week view, how does it decide which week to show? It doesn’t seem to go back to the week I was previously on, but maybe 1 week before or sometimes 2 weeks before.

Thank you.

No worries :wink:

Regarding the second question: when switching back from Monthly to Weekly view, the selectedDate is taken in consideration, which if initially not specified, defaults to today, and during navigation it is updated to the first day of the view.