Load Events from Google Calendar
Usage
theme="ios" You can turn auto theming on and let it decide based on the platform.
Usage
themeVariant="light" You can turn auto dark mode on based on system settings.
Usage
clickToCreate={true}
// click to create is on dragToCreate={true}
// drag to create is on dragToMove={true}
// reordering is on dragToResize={true}
// resizing is on eventDelete={true}
// deleting is on Fine-tune drag & drop with these options, which are false by default.
Usage
locale={localeEn} Selecting the locale loads the localized settings and the translated UI text.
Load Events from Google Calendar
Event data can be loaded from remote sources, like public google calendars. Through the integration plugin you can easily show events that are available in a public calendar. The integration plugin needs to be added to the download package or installed separately from a dedicated NPM package.
You will just need the CALENDAR_ID and an apiKey from google and you should be ready to roll.
In this example you can see how multiple public holiday calendars are loaded as separate resources into the timeline.
Public calendars are read-only. If you are interested in syncing private google calendars with read/write/delete access, check out this example.
Demo

Code
View code on GitHub
import { googleCalendarSync } from '@mobiscroll/calendar-integration';
import { Eventcalendar, setOptions, Toast } from '@mobiscroll/react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
function App() {
const [events, setEvents] = useState([]);
const [isToastOpen, setToastOpen] = useState(false);
const [toastMessage, setToastMessage] = useState('');
const firstDay = useRef();
const lastDay = useRef();
const calView = useMemo(
() => ({
timeline: {
type: 'month',
eventDisplay: 'fill',
},
}),
[],
);
const calendars = useMemo(
() => [
{ id: 'en.french#holiday@group.v.calendar.google.com', name: 'Holidays in France', color: '#D81B60' },
{ id: 'en.german#holiday@group.v.calendar.google.com', name: 'Holidays in Germany', color: '#F4511E' },
{ id: 'en.hungarian#holiday@group.v.calendar.google.com', name: 'Holidays in Hungary', color: '#AD1457' },
{ id: 'en.indian#holiday@group.v.calendar.google.com', name: 'Holidays in India', color: '#E4C441' },
{ id: 'en.romanian#holiday@group.v.calendar.google.com', name: 'Holidays in Romania', color: '#0B8043' },
{ id: 'en.uk#holiday@group.v.calendar.google.com', name: 'Holidays in United Kingdom', color: '#3F51B5' },
{ id: 'en.usa#holiday@group.v.calendar.google.com', name: 'Holidays in United States', color: '#8E24AA' },
],
[],
);
const calendarIds = useMemo(() => calendars.map((cal) => cal.id), [calendars]);
const onError = useCallback((resp) => {
setToastMessage(resp.error ? resp.error : resp.result.error.message);
setToastOpen(true);
}, []);
const loadEvents = useCallback(() => {
googleCalendarSync
.getEvents(calendarIds, firstDay.current, lastDay.current)
.then((resp) => {
resp.forEach((event) => {
event.resource = event.googleCalendarId;
});
setEvents(resp);
})
.catch(onError);
}, [calendarIds, firstDay, lastDay, onError]);
const handlePageLoading = useCallback(
(args) => {
const start = args.firstDay;
const end = args.lastDay;
// Calculate dates
// (pre-load events for previous and next pages as well)
firstDay.current = new Date(start.getFullYear(), start.getMonth() - 1, start.getDate());
lastDay.current = new Date(end.getFullYear(), end.getMonth() + 1, end.getDate());
loadEvents();
},
[loadEvents],
);
const handleCloseToast = useCallback(() => setToastOpen(false), []);
useEffect(() => {
googleCalendarSync.init({
apiKey: '<YOUR_GOOGLE_API_KEY>',
onInit: loadEvents,
});
}, [loadEvents]);
return (
<>
<Eventcalendar
clickToCreate={false}
dragToCreate={false}
exclusiveEndDates={true}
resources={calendars}
view={calView}
data={events}
onPageLoading={handlePageLoading}
/>
<Toast message={toastMessage} isOpen={isToastOpen} onClose={handleCloseToast} />
</>
);
}
export default App;
import { googleCalendarSync } from '@mobiscroll/calendar-integration';
import {
Eventcalendar,
MbscCalendarEvent,
MbscEventcalendarView,
MbscPageLoadingEvent,
setOptions,
Toast ,
} from '@mobiscroll/react';
import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
const App: FC = () => {
const [events, setEvents] = useState<MbscCalendarEvent[]>([]);
const [isToastOpen, setToastOpen] = useState<boolean>(false);
const [toastMessage, setToastMessage] = useState<string>('');
const firstDay = useRef<Date>(null);
const lastDay = useRef<Date>(null);
const calView = useMemo<MbscEventcalendarView>(
() => ({
timeline: {
type: 'month',
eventDisplay: 'fill',
},
}),
[],
);
const calendars = useMemo(
() => [
{ id: 'en.french#holiday@group.v.calendar.google.com', name: 'Holidays in France', color: '#D81B60' },
{ id: 'en.german#holiday@group.v.calendar.google.com', name: 'Holidays in Germany', color: '#F4511E' },
{ id: 'en.hungarian#holiday@group.v.calendar.google.com', name: 'Holidays in Hungary', color: '#AD1457' },
{ id: 'en.indian#holiday@group.v.calendar.google.com', name: 'Holidays in India', color: '#E4C441' },
{ id: 'en.romanian#holiday@group.v.calendar.google.com', name: 'Holidays in Romania', color: '#0B8043' },
{ id: 'en.uk#holiday@group.v.calendar.google.com', name: 'Holidays in United Kingdom', color: '#3F51B5' },
{ id: 'en.usa#holiday@group.v.calendar.google.com', name: 'Holidays in United States', color: '#8E24AA' },
],
[],
);
const calendarIds = useMemo(() => calendars.map((cal) => cal.id), [calendars]);
const onError = useCallback((resp: { error?: string; result: { error: { message: string } } }) => {
setToastMessage(resp.error ? resp.error : resp.result.error.message);
setToastOpen(true);
}, []);
const loadEvents = useCallback(() => {
googleCalendarSync
.getEvents(calendarIds, firstDay.current!, lastDay.current!)
.then((resp) => {
resp.forEach((event: MbscCalendarEvent) => {
event.resource = event.googleCalendarId;
});
setEvents(resp);
})
.catch(onError);
}, [calendarIds, firstDay, lastDay, onError]);
const handlePageLoading = useCallback(
(args: MbscPageLoadingEvent) => {
const start = args.firstDay;
const end = args.lastDay;
// Calculate dates
// (pre-load events for previous and next pages as well)
firstDay.current = new Date(start.getFullYear(), start.getMonth() - 1, start.getDate());
lastDay.current = new Date(end.getFullYear(), end.getMonth() + 1, end.getDate());
loadEvents();
},
[loadEvents],
);
const handleCloseToast = useCallback(() => setToastOpen(false), []);
useEffect(() => {
googleCalendarSync.init({
apiKey: '<YOUR_GOOGLE_API_KEY>',
onInit: loadEvents,
});
}, [loadEvents]);
return (
<>
<Eventcalendar
clickToCreate={false}
dragToCreate={false}
exclusiveEndDates={true}
resources={calendars}
view={calView}
data={events}
onPageLoading={handlePageLoading}
/>
<Toast message={toastMessage} isOpen={isToastOpen} onClose={handleCloseToast} />
</>
);
};
export default App;
.md-google-calendar .mbsc-timeline-day {
min-width: 150px;
}