---
title: "React Agenda Outlook Calendar Sync Example | Mobiscroll"
component: "Agenda"
framework: "React"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/react/agenda/sync-events-outlook-calendar"
---

# Outlook Calendar Sync - React Agenda demo

Use the React event calendar integration plugin to authenticate users, load their Outlook calendars, and display events in an agenda view. For React and Next.JS.

- [Live demo](https://demo.mobiscroll.com/react/agenda/sync-events-outlook-calendar)
- [View React JS code on GitHub](https://github.com/acidb/mobiscroll-demos-react/tree/main/src/demos/eventcalendar/agenda/sync-events-outlook-calendar)
- [View React TS code on GitHub](https://github.com/acidb/mobiscroll-demos-react-ts/tree/main/src/demos/eventcalendar/agenda/sync-events-outlook-calendar)
- This demo in other frameworks: [JavaScript](https://demo.mobiscroll.com/javascript/agenda/sync-events-outlook-calendar.md), [jQuery](https://demo.mobiscroll.com/jquery/agenda/sync-events-outlook-calendar.md), [Angular](https://demo.mobiscroll.com/angular/agenda/sync-events-outlook-calendar.md), [Vue](https://demo.mobiscroll.com/vue/agenda/sync-events-outlook-calendar.md)

## Description

The event calendar comes with third party calendar integration support through the [**integration plugin**](https://mobiscroll.com/docs/react/eventcalendar/calendar-integrations). This needs to be added to the download package or installed separately from a dedicated NPM package.

It includes everything you need to authenticate your users, get their Outlook calendars and provides functions for CRUD operations. It takes care of loading the events and converts them to the required format so that they can be displayed on the Mobiscroll calendar separately or mixed with other calendars and events.

Customizing the interaction, event workflows, whether the events are read-only is up to you. In this live demo, newly created events will land in the `primary calendar` of the authenticated user.

This example uses the [**integration plugin**](https://mobiscroll.com/docs/react/eventcalendar/calendar-integrations) to connect to and load events from Outlook Calendars and it is not available in the trial. Give the live demo a try and see how it can be configured.

## What this demo shows

- Shows a monthly agenda view with events listed and grouped by date.
- **Header navigation** The month and year label in the top left opens date navigation. The previous and next arrows and the Today button on the right move between months and jump back to the current date.
- **Signed-out state** No events are loaded by default. The `Sync My Outlook Calendars` button in the header prompts the user to sign in to Outlook Calendar.
- **Authentication flow** Clicking the Outlook sign-in button opens a new browser tab where the user can authenticate with their Outlook account.
- **Signed-in state** After sign-in, the header button changes to `My Calendars`.
- **Calendar list** The `My Calendars` popup shows multiple calendar switches, such as the user's personal calendar and country-specific holiday calendars.
- **Sign-out** The bottom of the popup includes a `Log out of my account` button for disconnecting the Outlook Calendar account.
- **Agenda list** The area below the header lists events for the selected month. Events in the agenda are grouped by date.
- **Sticky day headers** As the agenda scrolls vertically, each day stays visible with a sticky date header while its events appear underneath.
- **Events** Events appear as agenda cards with a colored strip on the left and the event title next to it. Start and end times are stacked on the right side of timed events. All-day events show the all-day label on the right.
- **Event interaction** Hovering an event highlights it.
- **Event selection** Clicking an event selects and highlights it.

## Best for

- **Personal calendar scheduling** Building agenda views where users can browse and manage events from their own Outlook Calendar.
- **Calendar visibility controls** Letting users toggle individual Outlook calendars on or off inside the same agenda view.
- **Readonly calendar handling** Displaying calendars without write access while preventing edits to those calendar rows.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-themeVariant) - option
- [`data`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-data) - option
- [`exclusiveEndDates`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-exclusiveEndDates) - option
- [`renderHeader`](https://mobiscroll.com/docs/react/eventcalendar/api#renderer-renderHeader) - renderer
- [`selectedDate`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-selectedDate) - option
- [`view`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-view) - option
- [`onPageLoading`](https://mobiscroll.com/docs/react/eventcalendar/api#event-onPageLoading) - event
- [`onSelectedDateChange`](https://mobiscroll.com/docs/react/eventcalendar/api#event-onSelectedDateChange) - event
- [`anchor`](https://mobiscroll.com/docs/react/popup/api#opt-anchor) - option
- [`display`](https://mobiscroll.com/docs/react/popup/api#opt-display) - option
- [`isOpen`](https://mobiscroll.com/docs/react/popup/api#opt-isOpen) - option
- [`scrollLock`](https://mobiscroll.com/docs/react/popup/api#opt-scrollLock) - option
- [`showOverlay`](https://mobiscroll.com/docs/react/popup/api#opt-showOverlay) - option
- [`touchUi`](https://mobiscroll.com/docs/react/popup/api#opt-touchUi) - option
- [`width`](https://mobiscroll.com/docs/react/popup/api#opt-width) - option
- [`onClose`](https://mobiscroll.com/docs/react/popup/api#event-onClose) - event
- [`onClose`](https://mobiscroll.com/docs/react/notifications/toast#event-onClose) - event

## Code

### JSX

```jsx
import { outlookCalendarSync } from '@mobiscroll/calendar-integration';
import {
  Button,
  CalendarNav,
  CalendarNext,
  CalendarPrev,
  Eventcalendar,
  Popup,
  setOptions,
  Switch,
  Toast,
} from '@mobiscroll/react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

function App() {
  const [calendarData, setCalendarData] = useState([]);
  const [calendarIds, setCalendarIds] = useState([]);
  const [isLoggedIn, setIsLoggedIn] = useState(false);
  const [isLoading, setLoading] = useState(false);
  const [isPopupOpen, setPopupOpen] = useState(false);
  const [isToastOpen, setToastOpen] = useState(false);
  const [myAnchor, setAnchor] = useState();
  const [myCalendars, setCalendars] = useState([]);
  const [myEvents, setEvents] = useState([]);
  const [mySelectedDate, setSelectedDate] = useState(new Date());
  const [toastMessage, setToastMessage] = useState('');

  const buttonRef = useRef();
  const startDate = useRef();
  const endDate = useRef();
  const timer = useRef();

  const myView = useMemo(() => ({ agenda: { type: 'month' } }), []);

  const handleError = useCallback((resp) => {
    setToastMessage(resp.message);
    setToastOpen(true);
  }, []);

  const handleToastClose = useCallback(() => {
    setToastOpen(false);
  }, []);

  const handlePopupClose = useCallback(() => {
    setPopupOpen(false);
  }, []);

  const handleSelectedDateChange = useCallback((args) => {
    setSelectedDate(args.date);
  }, []);

  const handlePageLoading = useCallback(
    (args) => {
      startDate.current = args.viewStart;
      endDate.current = args.viewEnd;
      clearTimeout(timer.current);
      timer.current = setTimeout(() => {
        if (outlookCalendarSync.isSignedIn()) {
          setLoading(true);
          outlookCalendarSync
            .getEvents(calendarIds, startDate.current, endDate.current)
            .then((resp) => {
              setEvents(resp);
              setLoading(false);
            })
            .catch(handleError);
        }
      }, 200);
    },
    [calendarIds, handleError],
  );

  const toggleCalendar = useCallback(
    (ev) => {
      const checked = ev.target.checked;
      const calendarId = ev.target.value;
      const updatedCalendarData = { ...calendarData, [calendarId]: { ...calendarData[calendarId], checked } };
      setCalendarData(updatedCalendarData);
      if (checked) {
        setLoading(true);
        setCalendarIds((oldCalendarIds) => [...oldCalendarIds, calendarId]);
        outlookCalendarSync
          .getEvents([calendarId], startDate.current, endDate.current)
          .then((events) => {
            setLoading(false);
            setEvents((oldEvents) => [...oldEvents, ...events]);
          })
          .catch(handleError);
      } else {
        setCalendarIds((oldCalendarIds) => oldCalendarIds.filter((id) => id !== calendarId));
        setEvents((oldEvents) => oldEvents.filter((event) => event.outlookCalendarId !== calendarId));
      }
    },
    [calendarData, handleError],
  );

  const openPopup = useCallback(() => {
    setAnchor(buttonRef.current.nativeElement);
    setPopupOpen(true);
  }, []);

  const navigate = useCallback(() => {
    setSelectedDate(new Date());
  }, []);

  const signIn = useCallback(() => {
    outlookCalendarSync.signIn().catch(handleError);
  }, [handleError]);

  const signOut = useCallback(() => {
    outlookCalendarSync.signOut().catch(handleError);
  }, [handleError]);

  const customHeader = useCallback(
    () => (
      <>
        <CalendarNav />
        <div className={'mds-loader' + (isLoading ? ' mds-loader-visible' : '')}></div>
        <div className="mbsc-flex mbsc-flex-1-0 mbsc-justify-content-end">
          {isLoggedIn ? (
            <Button ref={buttonRef} onClick={openPopup}>
              My Calendars
            </Button>
          ) : (
            <Button onClick={signIn}>Sync my Outlook calendars</Button>
          )}
          <Button onClick={navigate}>Today</Button>
        </div>
        <CalendarPrev />
        <CalendarNext />
      </>
    ),
    [isLoading, isLoggedIn, navigate, openPopup, signIn],
  );

  useEffect(() => {
    const onSignedIn = () => {
      setIsLoggedIn(true);
      outlookCalendarSync
        .getCalendars()
        .then((calendars) => {
          const newCalendarIds = [];
          const newCalendarData = {};

          calendars.sort((c) => (c.isDefaultCalendar ? -1 : 1));

          for (const c of calendars) {
            newCalendarIds.push(c.id);
            newCalendarData[c.id] = { checked: true };
          }

          setCalendarIds(newCalendarIds);
          setCalendarData(newCalendarData);
          setCalendars(calendars);
          setLoading(true);

          return outlookCalendarSync.getEvents(newCalendarIds, startDate.current, endDate.current);
        })
        .then((events) => {
          setEvents(events);
          setLoading(false);
        })
        .catch(handleError);
    };

    const onSignedOut = () => {
      setCalendars([]);
      setCalendarIds([]);
      setCalendarData({});
      setIsLoggedIn(false);
      setEvents([]);
      setPopupOpen(false);
    };

    // Init Outlook client
    outlookCalendarSync.init({
      clientId: '<YOUR_OUTLOOK_CLIENT_ID>',
      redirectUri: '<YOUR_OUTLOOK_REDIRECT_URI>',
      onSignedIn: onSignedIn,
      onSignedOut: onSignedOut,
    });
  }, [handleError]);

  return (
    <>
      <Eventcalendar
        data={myEvents}
        exclusiveEndDates={true}
        renderHeader={customHeader}
        selectedDate={mySelectedDate}
        view={myView}
        onPageLoading={handlePageLoading}
        onSelectedDateChange={handleSelectedDateChange}
      />
      <Popup
        anchor={myAnchor}
        contentPadding={false}
        display="anchored"
        isOpen={isPopupOpen}
        scrollLock={false}
        showOverlay={false}
        touchUi={false}
        width={400}
        onClose={handlePopupClose}
      >
        <div className="mbsc-form-group-inset">
          <div className="mbsc-form-group-title">My Calendars</div>
          {myCalendars.map((cal) => (
            <Switch label={cal.name} key={cal.id} value={cal.id} checked={calendarData[cal.id].checked} onChange={toggleCalendar} />
          ))}
        </div>
        <div className="mbsc-form-group-inset">
          <Button className="mbsc-button-block" onClick={signOut}>
            Sign out of my account
          </Button>
        </div>
      </Popup>
      <Toast isOpen={isToastOpen} message={toastMessage} onClose={handleToastClose} />
    </>
  );
}
export default App;
```

### TSX

```tsx
import { outlookCalendarSync } from '@mobiscroll/calendar-integration';
import {
  Button,
  CalendarNav,
  CalendarNext,
  CalendarPrev,
  Eventcalendar,
  MbscCalendarEvent,
  MbscEventcalendarView,
  MbscPageLoadingEvent,
  MbscSelectedDateChangeEvent,
  Popup,
  setOptions,
  Switch,
  Toast,
} from '@mobiscroll/react';
import { ChangeEvent, FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

const App: FC = () => {
  const [calendarData, setCalendarData] = useState<{ [key: string]: { checked: boolean } }>({});
  const [calendarIds, setCalendarIds] = useState<string[]>([]);
  const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
  const [isLoading, setLoading] = useState<boolean>(false);
  const [isPopupOpen, setPopupOpen] = useState<boolean>(false);
  const [isToastOpen, setToastOpen] = useState<boolean>(false);
  const [myAnchor, setAnchor] = useState<HTMLElement>();
  const [myCalendars, setCalendars] = useState<Array<{ name: string; id: string }>>([]);
  const [myEvents, setEvents] = useState<MbscCalendarEvent[]>([]);
  const [mySelectedDate, setSelectedDate] = useState(new Date());
  const [toastMessage, setToastMessage] = useState<string>('');

  const buttonRef = useRef<Button>(null);
  const startDate = useRef<Date>(null);
  const endDate = useRef<Date>(null);
  const timer = useRef<ReturnType<typeof setTimeout>>(undefined);

  const view = useMemo<MbscEventcalendarView>(() => ({ agenda: { type: 'month' } }), []);

  const handleError = useCallback((resp: { error?: string; result: { error: { message: string } } }) => {
    setToastMessage(resp.error ? resp.error : resp.result.error.message);
    setToastOpen(true);
  }, []);

  const handleToastClose = useCallback(() => {
    setToastOpen(false);
  }, []);

  const handlePopupClose = useCallback(() => {
    setPopupOpen(false);
  }, []);

  const handleSelectedDateChange = useCallback((event: MbscSelectedDateChangeEvent) => {
    setSelectedDate(new Date(event.date as string));
  }, []);

  const handlePageLoading = useCallback(
    (args: MbscPageLoadingEvent) => {
      clearTimeout(timer.current);
      startDate.current = args.viewStart;
      endDate.current = args.viewEnd;
      timer.current = setTimeout(() => {
        if (outlookCalendarSync.isSignedIn()) {
          setLoading(true);
          outlookCalendarSync
            .getEvents(calendarIds, startDate.current!, endDate.current!)
            .then((resp: MbscCalendarEvent[]) => {
              setEvents(resp);
              setLoading(false);
            })
            .catch(handleError);
        }
      }, 200);
    },
    [calendarIds, handleError],
  );

  const toggleCalendar = useCallback(
    (ev: ChangeEvent<HTMLInputElement>) => {
      const checked = ev.target.checked;
      const calendarId = ev.target.value;
      if (calendarData) {
        const updatedCalendarData = { ...calendarData, [calendarId]: { ...calendarData[calendarId], checked } };
        setCalendarData(updatedCalendarData);
      }
      if (checked) {
        setLoading(true);
        setCalendarIds((calIds) => [...calIds, calendarId]);
        outlookCalendarSync
          .getEvents([calendarId], startDate.current!, endDate.current!)
          .then((events) => {
            setLoading(false);
            setEvents((oldEvents) => [...oldEvents, ...events]);
          })
          .catch(handleError);
      } else {
        setCalendarIds((calIds) => calIds.filter((item) => item !== calendarId));
        setEvents((oldEvents) => oldEvents.filter((item) => item.outlookCalendarId !== calendarId));
      }
    },
    [calendarData, handleError],
  );

  const openPopup = useCallback(() => {
    setAnchor(buttonRef.current!.nativeElement);
    setPopupOpen(true);
  }, []);

  const navigate = useCallback(() => {
    setSelectedDate(new Date());
  }, []);

  const signIn = useCallback(() => {
    outlookCalendarSync.signIn().catch(handleError);
  }, [handleError]);

  const signOut = useCallback(() => {
    outlookCalendarSync.signOut().catch(handleError);
  }, [handleError]);

  const customHeader = useCallback(
    () => (
      <>
        <CalendarNav />
        <div className={'mds-loader' + (isLoading ? ' mds-loader-visible' : '')}></div>
        <div className="mbsc-flex mbsc-flex-1-0 mbsc-justify-content-end">
          {isLoggedIn ? (
            <Button ref={buttonRef} onClick={openPopup}>
              My Calendars
            </Button>
          ) : (
            <Button onClick={signIn}>Sync my outlook calendars</Button>
          )}
          <Button onClick={navigate}>Today</Button>
        </div>
        <CalendarPrev />
        <CalendarNext />
      </>
    ),
    [isLoading, isLoggedIn, navigate, openPopup, signIn],
  );

  useEffect(() => {
    const onSignedIn = () => {
      setIsLoggedIn(true);
      outlookCalendarSync
        .getCalendars()
        .then((calendars: { name: string; id: string; isDefaultCalendar: boolean }[]) => {
          const newCalendarIds: string[] = [];
          const newCalendarData: { [key: string]: { checked: boolean } } = {};

          calendars.sort((c) => (c.isDefaultCalendar ? -1 : 1));

          for (const c of calendars) {
            newCalendarIds.push(c.id);
            newCalendarData[c.id] = { checked: true };
          }

          setCalendarIds(newCalendarIds);
          setCalendarData(newCalendarData);
          setCalendars(calendars);
          setLoading(true);
          return outlookCalendarSync.getEvents(newCalendarIds, startDate.current!, endDate.current!);
        })
        .then((events: MbscCalendarEvent[]) => {
          setEvents(events);
          setLoading(false);
        })
        .catch(handleError);
    };

    const onSignedOut = () => {
      setIsLoggedIn(false);
      setCalendars([]);
      setCalendarIds([]);
      setCalendarData({});
      setEvents([]);
      setPopupOpen(false);
    };

    // Init Outlook client
    outlookCalendarSync.init({
      clientId: '<YOUR_OUTLOOK_CLIENT_ID>',
      redirectUri: '<YOUR_OUTLOOK_REDIRECT_URI>',
      onSignedIn: onSignedIn,
      onSignedOut: onSignedOut,
    });
  }, [handleError]);

  return (
    <>
      <Eventcalendar
        data={myEvents}
        exclusiveEndDates={true}
        renderHeader={customHeader}
        selectedDate={mySelectedDate}
        view={view}
        onPageLoading={handlePageLoading}
        onSelectedDateChange={handleSelectedDateChange}
      ></Eventcalendar>
      <Popup
        anchor={myAnchor}
        contentPadding={false}
        display="anchored"
        isOpen={isPopupOpen}
        scrollLock={false}
        showOverlay={false}
        touchUi={false}
        width={400}
        onClose={handlePopupClose}
      >
        <div className="mbsc-form-group-inset">
          <div className="mbsc-form-group-title">My Calendars</div>
          {myCalendars.map((cal) => (
            <Switch label={cal.name} key={cal.id} value={cal.id} checked={calendarData[cal.id].checked} onChange={toggleCalendar} />
          ))}
        </div>
        <div className="mbsc-form-group-inset">
          <Button className="mbsc-button-block" onClick={signOut}>
            Log out of my account
          </Button>
        </div>
      </Popup>
      <Toast isOpen={isToastOpen} message={toastMessage} onClose={handleToastClose} />
    </>
  );
};
export default App;
```

### CSS

```css
.mds-loader {
  width: 32px;
  height: 32px;
  border: 4px solid #8c8c8c;
  border-bottom-color: transparent;
  border-radius: 50%;
  display: inline-block;
  box-sizing: border-box;
  animation: mds-loader-rotation 1s linear infinite;
  visibility: hidden;
}

.mds-loader-visible {
  visibility: visible;
}

@keyframes mds-loader-rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
```

## Implementation notes

- This demo is structurally identical to `sync-events-google-calendar` with the following Outlook-specific differences:
- Install `@mobiscroll/calendar-integration`. Import `outlookCalendarSync`. Call `outlookCalendarSync.init({ clientId: '<YOUR_OUTLOOK_CLIENT_ID>', redirectUri: '<YOUR_OUTLOOK_REDIRECT_URI>', onSignedIn, onSignedOut })` at component init (no `apiKey`). Use `view: { agenda: { type: 'month' } }` with `exclusiveEndDates: true`.
- In `onSignedIn`: call `outlookCalendarSync.getCalendars()`. Calendars have a `name` property (not `summary`) and sort by `isDefaultCalendar` (not `primary`). Initialize `calendarIds` with all IDs, then call `outlookCalendarSync.getEvents(calendarIds, startDate, endDate)`.
- Toggling a calendar **on**: fetch only that single calendar's events - `outlookCalendarSync.getEvents([calendarId], startDate, endDate)` - and **append** the result to the existing events array. Toggling **off**: filter the events array by `event.outlookCalendarId !== calendarId` (no re-fetch needed).
- `onPageLoading`, custom header (sign-in button → "My Calendars" button after login), loading spinner, `Popup` with `Switch` list and "Sign out" button, `Toast` for errors, and "Today" button are all identical to `sync-events-google-calendar`.

## Run it in your project

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/react/getting-started/installation

## Related demos

- Previous: [Google Calendar Sync](https://demo.mobiscroll.com/react/agenda/sync-events-google-calendar.md) - Load and sync Google Calendar events in a React agenda view — authenticate users, toggle calendars on/off, and create events using the plugin.
- Next: [Load Public Google Calendar Events](https://demo.mobiscroll.com/react/agenda/load-events-from-google-calendar.md) - Load events from a public Google Calendar into the React agenda view using the integration plugin — connect with a Calendar ID and API key.
