ProSchedulerSign in

Timeline · Loading events

Load events on demand

Each month's assignments load when the month comes into view, from the range onPageChange reports.

Live demo

Page to next month

Fullscreen
import { useState } from "react"
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { monthStart, studioAssignments, studioResources, type StudioEvent } from "./data/studio"
import { useEvents } from "./kit"

export function TimelineOnDemandDemo() {
  const { events, setEvents, handlers } = useEvents<StudioEvent>([])
  const [status, setStatus] = useState("Loading…")

  return (
    <div className="docs-demo__stack">
      <p className="demo-status">{status}</p>
      <ProScheduler
        data={events}
        resources={studioResources}
        view={{ timeline: { type: "month" } }}
        onPageChange={({ firstDay }) => {
          setStatus("Loading…")
          // Stand-in for a request for this month's assignments.
          setTimeout(() => {
            const month = monthStart(firstDay)
            const loaded = studioAssignments(month).map((e) => ({ ...e, id: `${e.id}-${month.getTime()}` }))
            setEvents(loaded)
            setStatus(`${loaded.length} assignments for ${month.toLocaleDateString([], { month: "long", year: "numeric" })}`)
          }, 300)
        }}
        height={520}
        {...handlers}
      />
    </div>
  )
}

About this demo

Each month's assignments load when the month comes into view, from the range onPageChange reports.

Things to try

  • Page to next month

The props behind it are explained in Loading and saving events.

Use ProScheduler in your project