useSchedule
Learn how to use the useSchedule hook to manage subscriber notification schedules in your React application
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
| Prop | Type | Default |
|---|---|---|
onError? | (error: NovuError) => void | - |
onSuccess? | (data: Schedule) => void | - |
Return value
| Prop | Type | Default |
|---|---|---|
refetch? | () => Promise<void> | - |
isFetching? | boolean | true |
isLoading? | boolean | true |
error? | NovuError | undefined | - |
schedule? | Schedule | undefined | - |
Schedule type
The Schedule type from @novu/react includes these properties:
| Prop | Type | Default |
|---|---|---|
weeklySchedule? | object | - |
isEnabled? | boolean | - |
Schedule object structure.
Each DaySchedule object within weeklySchedule has the following structure:
| Prop | Type | Default |
|---|---|---|
hours? | Array<{ start: string; end: string; }> | - |
isEnabled? | boolean | - |
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.