React fullcalendar error cannot read property 'seg' of undefined

Viewed 1197

I'm getting the titled error using react fullcalendar on mobile view only. When I'm in desktop view everything is working fine. The code is the below:

function CalendarPage() {
  const [currentEvents, setCurrentEvents] = useState(INITIAL_EVENTS);
  console.log(currentEvents);

  const handleDateSelect = (selectInfo) => {
    let title = prompt('Please enter a new title for your event');
    let calendarApi = selectInfo.view.calendar;

    calendarApi.unselect(); // clear date selection

    if (title) {
      calendarApi.addEvent({
        id: createEventId(),
        title,
        start: selectInfo.startStr,
        end: selectInfo.endStr,
        allDay: selectInfo.allDay
      });
    }
  };

  const handleEventClick = (clickInfo) => {
    clickInfo.event.remove();
  };

  const handleEvents = (events) => {
    setCurrentEvents({
      currentEvents: events
    });
  };

  function renderEventContent(eventInfo) {
    return (
      <>
        <b>{eventInfo.timeText}</b>
        <i>{eventInfo.event.title}</i>
      </>
    );
  }

  return (
    <FullCalendar
      plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
      headerToolbar={{
        left: 'prev,next,today',
        center: 'title',
        right: 'dayGridMonth,timeGridWeek,timeGridDay'
      }}
      initialView='dayGridMonth'
      locale={el}
      editable={true}
      selectable={true}
      selectMirror={true}
      dayMaxEvents={true}
      weekends={true}
      initialEvents={currentEvents}
      select={handleDateSelect}
      eventContent={renderEventContent}
      eventClick={handleEventClick}
      eventsSet={handleEvents}
    />
  );
}

I have read the documentation and the GitHub page but unfortunately didn't find a solution.

I have create a codesandbox to reproduce the error: link

2 Answers

Add contentHeight: 'auto' to the configuration setup of the calendar. This happens on when the calendar renders on smaller sizes like mobile devices

As Ivan Rossouw had mentioned you need to change contentHeight to auto in the FullCalendar configuration set up. Here is an example with props:

  render() {
return (
  <div className='demo-app'>
    {this.renderSidebar()}
    <div className='demo-app-main'>
      <FullCalendar
        plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
        headerToolbar={{
          left: 'prev,next today',
          center: 'title',
          right: 'dayGridMonth,timeGridWeek,timeGridDay'
        }}
        initialView='dayGridMonth'
        contentHeight='auto'
        editable={true}
        selectable={true}
        selectMirror={true}
        dayMaxEvents={true}
        weekends={this.state.weekendsVisible}
        events={this.state.currentEvents}
        select={this.handleDateSelect}
        eventContent={renderEventContent} // custom render function
        eventClick={this.handleEventClick}
        // eventsSet={this.handleEvents} // called after events are initialized/added/changed/removed
        /* you can update a remote database when these fire:
        eventAdd={function(){}}
        eventChange={function(){}}
        eventRemove={function(){}}
        */
      />
    </div>
  </div>
)

}

Related