---
title: "React Scheduler Dynamic View Switching Example | Mobiscroll"
component: "Scheduler"
framework: "React"
library_version: "6.2.0"
url: "https://demo.mobiscroll.com/react/scheduler/switching-calendar-scheduler-agenda"
---

# Dynamic View Switching - React Scheduler demo

Switch between year, month, week, day, and agenda views in the React event calendar — via header control or programmatically. For React and Next.JS.

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

## Description

Dynamically switch views within one instance. Use a UI control to let users do the switching or do it programmatically.

The example features a month view with events as labels, a weekly schedule view, a daily schedule and a weekly agenda. Use property binding and when the value of the property changes the settings propagate.

## What this demo shows

- A desktop event calendar with a header segmented control for switching between year, month, week, day, and agenda views.
- **Header and segmented control** A segemnted control with `Year`, `Month`, `Week`, `Day` and `Agenda` options is positioned in the center of the header, between the year navigation label (quick navigation picker) on the left and the blue prev/next arrows with a `Today` button on the right.
- **Month view** The demo opens with the `Month` option selected and displays a desktop month view with event labels.
- **Event labels** Days with events show labels directly inside the month cells, with different colors and styles for all-day, multi-day, and timed events.
- **Overflow handling** When a day cell cannot show all events, additional events are collapsed into an `X more` label. Clicking the label opens a popover with the remaining events for that day.
- **Label interaction** Hovering or clicking an event label selects it and highlights the selected label.
- **Day cell states** Hovering an empty day cell highlights the day number with a gray background. Clicking the empty part of a cell selects the day and highlights the day number with a blue background.
- **Year view** Selecting `Year` shows all twelve months of the current year in a single scrollable layout.
- **Year view events** Days with events show a small label below the date. When multiple events are scheduled, an `X more` label opens a popover above the day cell with the events for that date.
- **Week view** Selecting `Week` shows a desktop weekly scheduler layout with a fixed week strip, a fixed all-day row, and a scrollable time grid for the selected week.
- **Week strip** The strip below the header shows the days of the selected week, with the current date highlighted by a blue circle.
- **Week events** Timed events appear in the scheduler grid as colored cards with a left color stripe, bold event title, and exact start and end time above the title.
- **Current time** A blue current-time line appears across the week time grid, with a small blue dot marking the current date.
- **Time indicator** Hovering over the week time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Day view** Selecting `Day` shows a desktop daily scheduler layout with a fixed week strip, a fixed all-day row, and a scrollable time grid for the selected day.
- **Day navigation** The week strip shows surrounding dates for quick day switching. Dates highlight on hover, and the selected day is marked with a blue circle.
- **Day events** Timed events appear in the daily scheduler grid as colored cards with a left color stripe, bold event title, and exact start and end time above the title.
- **Day current time** A blue current-time line appears across the daily time grid.
- **Day time indicator** Hovering over the daily time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Agenda view** Selecting `Agenda` shows a week calendar at the top and a daily agenda list below it.
- **Agenda selection** The agenda list displays events for the selected date. Selecting a different date in the week calendar updates the agenda automatically.
- **Agenda event markers** Days with events display a small marker below the day in the week calendar.
- **Event creation** Double-clicking or clicking and dragging in the event calendar or scheduler creates a new event.

## Best for

- **Multi-level schedule browsing** Apps where users need to move between year, month, week, day, and agenda views without leaving the same calendar instance.
- **Operational planning** Workflows that need both a broad overview of upcoming activity and detailed time-grid planning for a selected week or day.
- **Daily event review** Interfaces where users need to select a date and review that day's events in an agenda list.
- **Dense calendars** Schedules where month and year views need to handle days with more events than can fit visibly in the cell.
- **Interactive scheduling** Use cases where users create events directly from the calendar or scheduler grid.

## 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
- [`labels`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-labels) - option
- [`clickToCreate`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-clickToCreate) - option
- [`dragToCreate`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-dragToCreate) - option
- [`dragToMove`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-dragToMove) - option
- [`dragToResize`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-dragToResize) - option
- [`eventDelete`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-eventDelete) - option
- [`renderHeader`](https://mobiscroll.com/docs/react/eventcalendar/api#renderer-renderHeader) - renderer
- [`height`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-height) - option
- [`view`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-view) - option
- [`data`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-data) - option
- [`cssClass`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-cssClass) - option

## Code

### JSX

```jsx
import {
  CalendarNav,
  CalendarNext,
  CalendarPrev,
  CalendarToday,
  Eventcalendar,
  getJson,
  Segmented,
  SegmentedGroup,
  setOptions,
} from '@mobiscroll/react';
import { useCallback, useEffect, useState } from 'react';

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

function App() {
  const [view, setView] = useState('month');
  const [myEvents, setEvents] = useState([]);

  const [calView, setCalView] = useState({
    calendar: { labels: true },
  });

  const changeView = useCallback((event) => {
    let calView;

    switch (event.target.value) {
      case 'year':
        calView = {
          calendar: { type: 'year' },
        };
        break;
      case 'month':
        calView = {
          calendar: { labels: true },
        };
        break;
      case 'week':
        calView = {
          scheduler: { type: 'week' },
        };
        break;
      case 'day':
        calView = {
          scheduler: { type: 'day' },
        };
        break;
      case 'agenda':
        calView = {
          calendar: { type: 'week' },
          agenda: { type: 'week' },
        };
        break;
    }

    setView(event.target.value);
    setCalView(calView);
  }, []);

  const customWithNavButtons = useCallback(
    () => (
      <>
        <CalendarNav className="cal-header-nav" />
        <div className="cal-header-picker">
          <SegmentedGroup value={view} onChange={changeView}>
            <Segmented value="year">Year</Segmented>
            <Segmented value="month">Month</Segmented>
            <Segmented value="week">Week</Segmented>
            <Segmented value="day">Day</Segmented>
            <Segmented value="agenda">Agenda</Segmented>
          </SegmentedGroup>
        </div>
        <CalendarPrev className="cal-header-prev" />
        <CalendarToday className="cal-header-today" />
        <CalendarNext className="cal-header-next" />
      </>
    ),
    [changeView, view],
  );

  useEffect(() => {
    getJson(
      'https://trial.mobiscroll.com/events/?vers=5',
      (events) => {
        setEvents(events);
      },
      'jsonp',
    );
  }, []);

  return (
    <Eventcalendar
      clickToCreate={true}
      dragToCreate={true}
      dragToMove={true}
      dragToResize={true}
      eventDelete={true}
      renderHeader={customWithNavButtons}
      height={750}
      view={calView}
      data={myEvents}
      cssClass="md-switching-view-cont"
    />
  );
}

export default App;
```

### TSX

```tsx
import {
  CalendarNav,
  CalendarNext,
  CalendarPrev,
  CalendarToday,
  Eventcalendar,
  getJson,
  MbscCalendarEvent,
  MbscEventcalendarView,
  Segmented,
  SegmentedGroup,
  setOptions,
} from '@mobiscroll/react';
import { ChangeEvent, FC, useCallback, useEffect, useState } from 'react';

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

const App: FC = () => {
  const [view, setView] = useState('month');
  const [myEvents, setEvents] = useState<MbscCalendarEvent[]>([]);

  const [calView, setCalView] = useState<MbscEventcalendarView>({
    calendar: { labels: true },
  });

  const changeView = useCallback((event: ChangeEvent<HTMLInputElement>) => {
    let calView = {};

    switch (event.target.value) {
      case 'year':
        calView = {
          calendar: { type: 'year' },
        };
        break;
      case 'month':
        calView = {
          calendar: { labels: true },
        };
        break;
      case 'week':
        calView = {
          scheduler: { type: 'week' },
        };
        break;
      case 'day':
        calView = {
          scheduler: { type: 'day' },
        };
        break;
      case 'agenda':
        calView = {
          calendar: { type: 'week' },
          agenda: { type: 'week' },
        };
        break;
    }

    setView(event.target.value);
    setCalView(calView);
  }, []);

  const customWithNavButtons = useCallback(
    () => (
      <>
        <CalendarNav className="cal-header-nav" />
        <div className="cal-header-picker">
          <SegmentedGroup value={view} onChange={changeView}>
            <Segmented value="year">Year</Segmented>
            <Segmented value="month">Month</Segmented>
            <Segmented value="week">Week</Segmented>
            <Segmented value="day">Day</Segmented>
            <Segmented value="agenda">Agenda</Segmented>
          </SegmentedGroup>
        </div>
        <CalendarPrev className="cal-header-prev" />
        <CalendarToday className="cal-header-today" />
        <CalendarNext className="cal-header-next" />
      </>
    ),
    [changeView, view],
  );

  useEffect(() => {
    getJson(
      'https://trial.mobiscroll.com/events/?vers=5',
      (events: MbscCalendarEvent[]) => {
        setEvents(events);
      },
      'jsonp',
    );
  }, []);

  return (
    <Eventcalendar
      clickToCreate={true}
      dragToCreate={true}
      dragToMove={true}
      dragToResize={true}
      eventDelete={true}
      renderHeader={customWithNavButtons}
      height={750}
      view={calView}
      data={myEvents}
      cssClass="md-switching-view-cont"
    />
  );
};
export default App;
```

### CSS

```css
.md-switching-view-cont .mbsc-segmented {
  max-width: 350px;
  margin: 0 auto;
}

.md-switching-view-cont .mbsc-calendar-grid-item {
  height: 490px;
  box-sizing: border-box;
}

.cal-header-picker {
  flex: 1 0 auto;
}

.cal-header-nav {
  width: 200px;
}

/* material header order */

.mbsc-material.cal-header-prev {
  order: 1;
}

.mbsc-material.cal-header-next {
  order: 2;
}

.mbsc-material.cal-header-nav {
  order: 3;
}

.mbsc-material .cal-header-picker {
  order: 4;
}

.mbsc-material .cal-header-today {
  order: 5;
}

/* windows header order */

.mbsc-windows.cal-header-nav {
  order: 1;
}

.mbsc-windows.cal-header-prev {
  order: 2;
}

.mbsc-windows.cal-header-next {
  order: 3;
}

.mbsc-windows .cal-header-picker {
  order: 4;
}

.mbsc-windows .cal-header-today {
  order: 5;
}
```

## Implementation notes

- Define five view configurations to switch between:
  - **Year**: `{ calendar: { type: 'year' } }`
  - **Month**: `{ calendar: { labels: true } }` (initial view)
  - **Week**: `{ scheduler: { type: 'week' } }`
  - **Day**: `{ scheduler: { type: 'day' } }`
  - **Agenda**: `{ calendar: { type: 'week' }, agenda: { type: 'week' } }`
- Use `renderHeader` (Angular: `headerTemplate`, Vue: `#header` slot) to render a `SegmentedGroup` in the custom header with one option per view. On selection, update the active view; for the imperative API, call `inst.setOptions({ view: newViewConfig })`.
- Load events from `https://trial.mobiscroll.com/events/?vers=5` via JSONP using `getJson(url, callback, 'jsonp')`. For the imperative API, call `inst.setEvents(events)` in the callback.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-react.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config react
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config react --trial`.

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: [Color-Coded Time Blocks](https://demo.mobiscroll.com/react/scheduler/colored-cell-background.md) - Color React Scheduler cell backgrounds for time ranges — mark lunch breaks, maintenance windows, or recurring schedules.
- Next: [Visible hours and days](https://demo.mobiscroll.com/react/scheduler/show-hide-hours-days.md) - Keep your calendar focused. Trim your view. In React, you can show only weekdays and business hours, making schedules cleaner and faster.
