Skip to main content

Schedules define when notifications should be delivered by setting availability hours across days of the week. The useSchedule hook provides a way to fetch, display, and update the notification schedule for the current subscriber.

Hook parameters#

PropertyTypeDescription
onSuccess(data: Schedule) => voidCallback function called when the schedule is successfully fetched
onError(error: NovuError) => voidCallback function called when an error occurs

Return value#

PropertyTypeDescription
schedule`Scheduleundefined`
error`NovuErrorundefined`
isLoadingbooleanTrue during the initial load, false otherwise (default: true)
isFetchingbooleanTrue while any request is in flight (initial load or refetch), false otherwise (default: true)
refetch() => Promise<void>Function to manually trigger a refetch of the schedule

Schedule type#

The Schedule type from @novu/react includes these properties:

PropertyTypeDescription
isEnabledbooleanGlobal flag to enable or disable the entire schedule.
weeklyScheduleobjectAn object containing the schedule for each day of the week (for example, monday, tuesday). Each key holds a DaySchedule object.

Schedule object structure.#

Each DaySchedule object within weeklySchedule has the following structure:

PropertyTypeDescription
isEnabledbooleanFlag to enable or disable the schedule for this specific day.
hoursArray<{ start: string; end: string; }>An array of time ranges for when notifications are allowed. Multiple ranges per day are supported (for example, 9-12 AM and 2-5 PM).

Updating the schedule#

The hook also allows updating the subscriber’s schedule via schedule.update:

Example usage#

Here’s how to use the useSchedule hook to display and update a subscriber’s notification schedule. The schedule.update() method creates a schedule if one doesn’t exist or updates the existing one.