Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
Cannot read properties of null (reading 'getApi') in FullCalendar.io reactjs

i'm new to ReactJs and i'm trying to class component of FullCalendar to a functional component i watched some tutorials but when i did it i keep getting this error

Uncaught TypeError: Cannot read properties of null (reading 'getApi')

and i searched for a functional component for the FullCalendar but i didn't find anything useful this is my class component:

import React from "react";
import FullCalendar from "@fullcalendar/react";
import './Fullcalendar.css'
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin from "@fullcalendar/interaction"; // needed for dayClick
export default class DemoApp extends React.Component {
calendarComponentRef = React.createRef();

state = {
calendarWeekends: true,
calendarEvents: [
  // initial event data
  { title: "Event Now", start: "2022-03-21", backgroundColor: "red" }
]
};
render() {    
    setTimeout(() => {
       let calendarApi = this.calendarComponentRef.current.getApi();
       calendarApi.gotoDate(this.props.date); // call a method on the Calendar object
    });
     return (
  <div>
  <div className="demo-app">
    <div className="demo-app-calendar">
        <FullCalendar
       id="fullCalendar"
       contentHeight={720}
       firstDay={1}
        defaultView="dayGridMonth"
        plugins={[dayGridPlugin, interactionPlugin]}
        ref={this.calendarComponentRef}
        events={this.state.calendarEvents}
      />
    </div>
  </div>
  </div>
);
 }
  }

and this is what i did to converted to a functional component:

    import React, { useRef } from "react";
    import FullCalendar from "@fullcalendar/react";
    import './Fullcalendar.css'
    import dayGridPlugin from "@fullcalendar/daygrid";
    import interactionPlugin from "@fullcalendar/interaction"; // needed for dayClick
    function Fullcalendar({date}) {

    const calendarComponentRef = useRef(null);
    setTimeout(() => {
    let calendarApi = calendarComponentRef.current.getApi();
    calendarApi.gotoDate(date); 
      });

     return (
       <div>
      <div className="demo-app">
      <div className="demo-app-calendar">
          <FullCalendar
         id="fullCalendar"
         contentHeight={720}
         firstDay={1}
          defaultView="dayGridMonth"
          plugins={[dayGridPlugin, interactionPlugin]}
          ref={calendarComponentRef}
        />
      </div>
    </div>
    </div>
  )
}

export default Fullcalendar

i tried and i searched but i don't know what i have to do.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It seems that you are setting a timeout which has no time associated, so it will run immediately. It tries to get the calendar component, but that seems to be before you've even returned the calendar component from your function, so I would expect that the calendar object doesn't exist yet, which is why your code can't find it.

Also, all you're doing with that API object is immediately setting the calendar date, but that's something you can do directly within the calendar options, if you want the calendar to start at a specific date.

Why not simply add

initialDate={date}

to the options in the <FullCalendar section instead?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda