Blog>
Snippets

Adding FullCalendar for Event Scheduling

Demonstrate how to integrate FullCalendar library into a Next.js application to create and display events in a calendar.
import FullCalendar from '@fullcalendar/react';
import dayGridPlugin from '@fullcalendar/daygrid';

export default function CalendarComponent() {
  const events = [
    { title: 'Event 1', date: '2023-04-01' },
    { title: 'Event 2', date: '2023-04-02' }
  ];

  return (
    <FullCalendar
      plugins={[dayGridPlugin]}
      initialView='dayGridMonth'
      events={events}
    />
  );
}
This code imports the necessary components from FullCalendar and defines a basic CalendarComponent. Inside the component, it declares a list of events and renders the FullCalendar component with dayGridPlugin to display a monthly view grid, initializing the view and passing the events to the calendar.
// In _app.js or your main application file
import '../node_modules/@fullcalendar/common/main.css';
import '../node_modules/@fullcalendar/daygrid/main.css';

// ...Rest of your _app.js file
Include the required CSS files of FullCalendar in your Next.js application. This is typically done in the _app.js file, which is the main component that wraps around your pages. This ensures that FullCalendar's styling is included in the global scope of your application.