---
title: "React Timeline Day/Week View Switcher Example | Mobiscroll"
component: "Timeline"
framework: "React"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/react/timeline/switching-day-week-work-week-timeline"
---

# Day/Week View Switcher - React Timeline demo

Build resource schedules with day, work-week, and full-week views on a React Timeline — switch views from the header to control time-grid detail. For React and Next.JS.

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

## Description

Scheduling people, teams or an entire workforce requires different views. Sometimes you'll be needing a helicopter view of a week and other times you might want to dig into a specific day. This all can be served through a simple switching mechanism implemented with a segmented control right in the header of the calendar.

By [dynamically changing the options](https://mobiscroll.com/docs/react/eventcalendar/api) you can set the level of detail you want to see. *Eg. Show a daily timeline with hourly steps, show the work week with the same resolution or zoom out for a full week-view with 12 hour steps.*

**Want to see how to set other views?** [Check out this example for switching views →](https://demo.mobiscroll.com/react/scheduler/switching-calendar-scheduler-agenda)

## What this demo shows

- A desktop scheduler timeline with days arranged horizontally and resources listed as rows on the left.
- **Header navigation** The month and year label opens date navigation, the previous and next buttons move between weeks, and the Today button returns to the current date.
- **View switcher** The header includes Day, Work week, and Week options, with Week selected by default.
- **Day view** Selecting Day updates the timeline to a single-day timeline view.
- **Work week view** Selecting Work week updates the timeline to show Monday through Friday.
- **Week view** Selecting Week updates the timeline to show a full Sunday-to-Saturday week.
- **Week strip** The strip below the header shows the selected week from Sunday to Saturday, with the current date highlighted.
- **Time grid** The timeline displays hourly columns across the visible day range.
- **Invalid time ranges** Early-morning and late-evening hours are blocked on weekdays, appear with a gray background, and do not allow event creation or event movement.
- **Invalid weekend** Saturdays and Sundays are blocked, so the weekend columns appear with a gray background and do not allow event creation.
- **Resources** Each resource is displayed as a separate timeline row with an avatar, person name, and job title.
- **Current time** A vertical blue line with a time label marks the current time.
- **Hover behavior** Hovering over the time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Event cards** Events are shown as colored cards with a left color stripe, bold title, and time range.
- **Date positioning** Events are positioned by their assigned resource, date, start time, and end time.
- **Event interaction** Events highlight on hover and expose drag and resize handles for moving the event or changing its duration.
- **Event selection** Clicking an event selects and highlights it.
- **Event creation** New events can be created by double-clicking the timeline or by clicking and dragging across a time range.
- **Scrolling** The timeline supports horizontal and vertical scrolling for navigating through time and resources.

## Best for

- **Workforce scheduling** Switching between day, work-week, and full-week views for teams that need both detailed daily planning and broader weekly coverage.
- **Resource planning** Assigning events to people, teams, rooms, equipment, or other resources that need separate rows in a timeline.
- **Shift and availability planning** Blocking non-working hours and weekends so users schedule only inside allowed time ranges.
- **Operational calendars** Reviewing many scheduled items across multiple resources while keeping resource details visible on the left.
- **Staffing dashboards** Showing names, roles, and avatars next to each resource so planners can identify the right person quickly.
- **Drag-and-drop scheduling flows** Creating, moving, and resizing events directly on the timeline while preventing updates in invalid time ranges.

## 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
- [`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
- [`view`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-view) - option
- [`data`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-data) - option
- [`invalid`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-invalid) - option
- [`resources`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-resources) - option
- [`renderHeader`](https://mobiscroll.com/docs/react/eventcalendar/api#renderer-renderHeader) - renderer
- [`renderResource`](https://mobiscroll.com/docs/react/eventcalendar/api#renderer-renderResource) - renderer
- [`onEventCreateFailed`](https://mobiscroll.com/docs/react/eventcalendar/api#event-onEventCreateFailed) - event
- [`onEventUpdateFailed`](https://mobiscroll.com/docs/react/eventcalendar/api#event-onEventUpdateFailed) - event
- [`cssClass`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-cssClass) - option
- [`onClose`](https://mobiscroll.com/docs/react/notifications/toast#event-onClose) - event

## Code

### JSX

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

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

function App() {
  const [myEvents, setEvents] = useState([]);
  const [view, setView] = useState('week');
  const [isToastOpen, setToastOpen] = useState(false);
  const [calView, setCalView] = useState({
    timeline: {
      type: 'week',
    },
  });

  const myResources = useMemo(
    () => [
      {
        id: 1,
        name: 'Ryan',
        color: '#ff0101',
        title: 'Cloud System Engineer',
        img: 'https://img.mobiscroll.com/demos/m1.png',
      },
      {
        id: 2,
        name: 'Kate',
        color: '#239a21',
        title: 'Help Desk Specialist',
        img: 'https://img.mobiscroll.com/demos/f1.png',
      },
      {
        id: 3,
        name: 'John',
        color: '#8f1ed6',
        title: 'Application Developer',
        img: 'https://img.mobiscroll.com/demos/m2.png',
      },
      {
        id: 4,
        name: 'Mark',
        color: '#01adff',
        title: 'Network Administrator',
        img: 'https://img.mobiscroll.com/demos/m3.png',
      },
      {
        id: 5,
        name: 'Sharon',
        color: '#d8ca1a',
        title: 'Data Quality Manager',
        img: 'https://img.mobiscroll.com/demos/f2.png',
      },
    ],
    [],
  );

  const myInvalids = useMemo(
    () => [
      {
        start: '00:00',
        end: '06:00',
        recurring: {
          repeat: 'weekly',
          weekDays: 'MO,TU,WE,TH,FR',
        },
      },
      {
        start: '20:00',
        end: '23:59',
        recurring: {
          repeat: 'weekly',
          weekDays: 'MO,TU,WE,TH,FR',
        },
      },
      {
        recurring: {
          repeat: 'weekly',
          weekDays: 'SA,SU',
        },
      },
    ],
    [],
  );

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

    switch (event.target.value) {
      case 'day':
        calView = {
          timeline: { type: 'day' },
        };
        break;
      case 'workweek':
        calView = {
          timeline: {
            type: 'week',
            startDay: 1,
            endDay: 5,
          },
        };
        break;
      case 'week':
      default:
        calView = {
          timeline: {
            type: 'week',
          },
        };
        break;
    }

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

  const renderMyHeader = useCallback(
    () => (
      <>
        <CalendarNav className="md-work-week-nav" />
        <div className="md-work-week-picker">
          <SegmentedGroup value={view} onChange={changeView}>
            <Segmented value="day">Day</Segmented>
            <Segmented value="workweek">Work week</Segmented>
            <Segmented value="week">Week</Segmented>
          </SegmentedGroup>
        </div>
        <CalendarPrev className="md-work-week-prev" />
        <CalendarToday className="md-work-week-today" />
        <CalendarNext className="md-work-week-next" />
      </>
    ),
    [changeView, view],
  );

  const renderMyResource = useCallback(
    (resource) => (
      <div className="md-work-week-cont">
        <div className="md-work-week-name">{resource.name}</div>
        <div className="md-work-week-title">{resource.title}</div>
        <img className="md-work-week-avatar" src={resource.img} alt="Avatar" />
      </div>
    ),
    [],
  );

  const handleEventUpdateFail = useCallback(() => {
    setToastOpen(true);
  }, []);

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

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

  return (
    <div>
      <Eventcalendar
        clickToCreate={true}
        dragToCreate={true}
        dragToMove={true}
        dragToResize={true}
        eventDelete={true}
        view={calView}
        data={myEvents}
        invalid={myInvalids}
        resources={myResources}
        renderHeader={renderMyHeader}
        renderResource={renderMyResource}
        onEventCreateFailed={handleEventUpdateFail}
        onEventUpdateFailed={handleEventUpdateFail}
        cssClass="md-switching-timeline-view-cont"
      />
      <Toast message="Can't schedule outside of working hours" isOpen={isToastOpen} onClose={handleCloseToast} />
    </div>
  );
}

export default App;
```

### TSX

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

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

const App: FC = () => {
  const [view, setView] = useState<string>('week');
  const [myEvents, setEvents] = useState<MbscCalendarEvent[]>([]);
  const [isToastOpen, setToastOpen] = useState<boolean>(false);
  const [calView, setCalView] = useState<MbscEventcalendarView>({
    timeline: {
      type: 'week',
    },
  });

  const myResources = useMemo<MbscResource[]>(
    () => [
      {
        id: 1,
        name: 'Ryan',
        color: '#ff0101',
        title: 'Cloud System Engineer',
        img: 'https://img.mobiscroll.com/demos/m1.png',
      },
      {
        id: 2,
        name: 'Kate',
        color: '#239a21',
        title: 'Help Desk Specialist',
        img: 'https://img.mobiscroll.com/demos/f1.png',
      },
      {
        id: 3,
        name: 'John',
        color: '#8f1ed6',
        title: 'Application Developer',
        img: 'https://img.mobiscroll.com/demos/m2.png',
      },
      {
        id: 4,
        name: 'Mark',
        color: '#01adff',
        title: 'Network Administrator',
        img: 'https://img.mobiscroll.com/demos/m3.png',
      },
      {
        id: 5,
        name: 'Sharon',
        color: '#d8ca1a',
        title: 'Data Quality Manager',
        img: 'https://img.mobiscroll.com/demos/f2.png',
      },
    ],
    [],
  );

  const myInvalids = useMemo(
    () => [
      {
        start: '00:00',
        end: '06:00',
        recurring: {
          repeat: 'weekly',
          weekDays: 'MO,TU,WE,TH,FR',
        },
      },
      {
        start: '20:00',
        end: '23:59',
        recurring: {
          repeat: 'weekly',
          weekDays: 'MO,TU,WE,TH,FR',
        },
      },
      {
        recurring: {
          repeat: 'weekly',
          weekDays: 'SA,SU',
        },
      },
    ],
    [],
  );

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

    switch (event.target.value) {
      case 'day':
        calView = {
          timeline: { type: 'day' },
        };
        break;
      case 'workweek':
        calView = {
          timeline: {
            type: 'week',
            startDay: 1,
            endDay: 5,
          },
        };
        break;
      case 'week':
      default:
        calView = {
          timeline: {
            type: 'week',
          },
        };
        break;
    }

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

  const renderMyHeader = useCallback(
    () => (
      <>
        <CalendarNav className="md-work-week-nav" />
        <div className="md-work-week-picker">
          <SegmentedGroup value={view} onChange={changeView}>
            <Segmented value="day">Day</Segmented>
            <Segmented value="workweek">Work week</Segmented>
            <Segmented value="week">Week</Segmented>
          </SegmentedGroup>
        </div>
        <CalendarPrev className="md-work-week-prev" />
        <CalendarToday className="md-work-week-today" />
        <CalendarNext className="md-work-week-next" />
      </>
    ),
    [changeView, view],
  );

  const renderMyResource = useCallback(
    (resource: MbscResource) => (
      <div className="md-work-week-cont">
        <div className="md-work-week-name">{resource.name}</div>
        <div className="md-work-week-title">{resource.title}</div>
        <img className="md-work-week-avatar" src={resource.img} alt="Avatar" />
      </div>
    ),
    [],
  );

  const handleEventUpdateFail = useCallback(() => {
    setToastOpen(true);
  }, []);

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

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

  return (
    <div>
      <Eventcalendar
        view={calView}
        data={myEvents}
        invalid={myInvalids}
        resources={myResources}
        renderHeader={renderMyHeader}
        renderResource={renderMyResource}
        onEventCreateFailed={handleEventUpdateFail}
        onEventUpdateFailed={handleEventUpdateFail}
        cssClass="md-switching-timeline-view-cont"
      />
      <Toast message="Can't schedule outside of working hours" isOpen={isToastOpen} onClose={handleCloseToast} />
    </div>
  );
};
export default App;
```

### CSS

```css
.md-work-week-cont {
  position: relative;
  padding-left: 50px;
}

.md-work-week-avatar {
  position: absolute;
  max-height: 50px;
  max-width: 50px;
  top: 21px;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  left: 20px;
}

.md-work-week-name {
  font-size: 16px;
}

.md-work-week-title {
  font-size: 12px;
  margin-top: 5px;
}

.md-switching-timeline-view-cont .mbsc-segmented {
  max-width: 350px;
  margin: 0 auto;
  padding: 1px;
}

.md-work-week-picker {
  flex: 1 0 auto;
}

.md-work-week-nav {
  width: 200px;
}

.md-switching-timeline-view-cont .mbsc-timeline-resource {
  display: flex;
  align-items: center;
}

.md-switching-timeline-view-cont .mbsc-timeline-resource-col {
  width: 205px;
}

/* material header order */

.mbsc-material.md-work-week-prev {
  order: 1;
}

.mbsc-material.md-work-week-next {
  order: 2;
}

.mbsc-material.md-work-week-nav {
  order: 3;
}

.mbsc-material .md-work-week-picker {
  order: 4;
}

.mbsc-material .md-work-week-today {
  order: 5;
}

/* windows header order */

.mbsc-windows.md-work-week-nav {
  order: 1;
}

.mbsc-windows.md-work-week-prev {
  order: 2;
}

.mbsc-windows.md-work-week-next {
  order: 3;
}

.mbsc-windows .md-work-week-picker {
  order: 4;
}

.mbsc-windows .md-work-week-today {
  order: 5;
}
```

## Implementation notes

- Set `timeline: { type: 'week' }` as the default view. The three switchable views are:
  - **Day**: `timeline: { type: 'day' }`
  - **Work week**: `timeline: { type: 'week', startDay: 1, endDay: 5 }`
  - **Week** (default): `timeline: { type: 'week' }`
- Use `renderHeader` (Angular: `headerTemplate`, Vue: `#header` slot) with the same structure as the event-listing demo: `CalendarNav`, a centered `SegmentedGroup` with three `Segmented` options (`day` / `workweek` / `week`), then `CalendarPrev`, `CalendarToday`, `CalendarNext`. When the selection changes, replace the active view config accordingly.
- Define 5 people resources, each with `id`, `name`, `color`, a `title` (job title string), and an `img` (avatar URL from `https://img.mobiscroll.com/demos/`).
- Use `renderResource` (Angular: `resourceTemplate`, Vue: `#resource` slot) to render a custom resource label showing the person's avatar, name, and job title.
- Define an `invalid` array to block off non-working time on all resources:
  - `{ start: '00:00', end: '06:00', recurring: { repeat: 'weekly', weekDays: 'MO,TU,WE,TH,FR' } }` - early morning
  - `{ start: '20:00', end: '23:59', recurring: { repeat: 'weekly', weekDays: 'MO,TU,WE,TH,FR' } }` - late evening
  - `{ recurring: { repeat: 'weekly', weekDays: 'SA,SU' } }` - full weekend
- Handle `onEventCreateFailed` and `onEventUpdateFailed` by showing a `Toast` with the message "Can't schedule outside of working hours". This fires when drag-to-create or drag-to-move lands in an invalid slot.
- Load events remotely via `getJson` from the trial endpoint.

## 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: [Daily Event Listing](https://demo.mobiscroll.com/react/timeline/event-listing.md) - Show events as full-day labels on a React Timeline — useful for spotting overloaded resources and managing schedules without an hourly time grid.
- Next: [Data & Display Timezone](https://demo.mobiscroll.com/react/timeline/setting-the-timezone.md) - Set separate data and display timezones on a React Timeline — configure per-resource event timezone display using Luxon, Moment-timezone, or Day.js.
