Skip to content

Quick start with React

Render a week view with a few events, then let people drag them around.

The calendar needs a date adapter. This guide uses date-fns; the others work the same way.

Terminal window
npm install @weekwise/react @weekwise/adapter-date-fns date-fns

Wrap the calendar in a DateLocalizationProvider with an adapter. Then tell the calendar how to read your events: a key and a start–end pair. The children render one event card.

Result· drag, resize, or draw a new event
import { useState } from "react";
import Calendar, { DateLocalizationProvider } from "@weekwise/react";
import { DateFnsAdapter } from "@weekwise/adapter-date-fns";
import "@weekwise/react/styles.css";
type Event = { id: string; title: string; start: Date; end: Date };
export function Schedule({ initial }: { initial: Event[] }) {
const [events, setEvents] = useState(initial);
return (
<DateLocalizationProvider adapter={DateFnsAdapter}>
<Calendar
style={{ height: 600 }}
scrollable
items={events}
eventKeyResolver={(event) => event.id}
eventTimeFrameResolver={(event) => ({ start: event.start, end: event.end })}
onEventChange={(event, start, end) =>
setEvents((prev) => prev.map((e) => (e.id === event.id ? { ...e, start, end } : e)))
}
onEventCreate={(start, end) =>
setEvents((prev) => [...prev, { id: crypto.randomUUID(), title: "New event", start, end }])
}
>
{(event) => <div>{event.title}</div>}
</Calendar>
</DateLocalizationProvider>
);
}

adapter accepts either a class (DateFnsAdapter) or a ready instance (new DateFnsAdapter({ locale: fr })). Create the instance outside the component, or memoize it, so the context value stays stable.