Great, thanks for the update.
Yes, you can use controlRef
in the Lite version. It works in Next.js as well:
'use client';
import React, {useEffect, useRef, useState} from "react";
import {DayPilot, DayPilotScheduler} from "@daypilot/daypilot-lite-react";
export default function Scheduler() {
const [scheduler, setScheduler] = useState<DayPilot.Scheduler>();
// ...
const onTimeRangeSelected = async (args: DayPilot.SchedulerTimeRangeSelectedArgs) => {
const modal = await DayPilot.Modal.prompt("Create a new event:", "Event 1");
scheduler?.clearSelection();
if (modal.canceled) {
return;
}
scheduler?.events.add({
start: args.start,
end: args.end,
id: DayPilot.guid(),
text: modal.result,
resource: args.resource
});
};
return (
<div>
<DayPilotScheduler
...
onTimeRangeSelected={onTimeRangeSelected}
controlRef={setScheduler}
/>
</div>
)
}
You can also use the standard ref
but that way you get a reference to the DayPilotScheduler
React component, not the DayPilot.Scheduler
instance. So the usage would be slightly different:
'use client';
import React, {useEffect, useRef, useState} from "react";
import {DayPilot, DayPilotScheduler} from "@daypilot/daypilot-lite-react";
export default function Scheduler() {
const schedulerRef = useRef<DayPilotScheduler>(null);
const onTimeRangeSelected = async (args: DayPilot.SchedulerTimeRangeSelectedArgs) => {
const modal = await DayPilot.Modal.prompt("Create a new event:", "Event 1");
schedulerRef.current?.control.clearSelection();
if (modal.canceled) {
return;
}
schedulerRef.current?.control.events.add({
start: args.start,
end: args.end,
id: DayPilot.guid(),
text: modal.result,
resource: args.resource
});
};
return (
<div>
<DayPilotScheduler
...
onTimeRangeSelected={onTimeRangeSelected}
ref={schedulerRef}
/>
</div>
)
}