I'm using the timeline view of FullCalendar v5 and @fullcalendar/react and I want my clanedar to automatically to scroll to today. When I call .gotoDate() it doesn't do anything.
Here is my calendar code:
const calendarRef = useRef();
const getCalendarApi = () => {
const {current} = calendarRef;
return current?.getApi();
};
return (
<FullCalendar
ref={calendarRef}
timeZone="local"
initialView="resourceTimelineMonth"
...
/>
);
Here is the code I'm using to call gotoDate():
<button
type="button"
onClick={() => {
const calendarApi = getCalendarApi();
calendarApi.gotoDate(new Date());
}}
>
test
</button>
When I click the "test" button, nothing happens. I checked and calendarApi.gotoDate() is a valid function it's just not doing anything. Any ideas why this isn't working?
UPDATE #1:
I also tried adding initialDate="2021-03-23" to the <FullCalendar /> but it also doesn't do anything
UPDATE #2:
I tried adding validRange and it worked in that it scrolled to the start date but now it's not showing me any events before the start date.
return (
<FullCalendar
ref={calendarRef}
timeZone="local"
initialView="resourceTimelineMonth"
validRange={()=> {
return {
start: "2021-03-20",
end: "2021-03-31"
};
}}
...
/>
);