RoomKitFrontend
useRecurrence
Fetch a recurrence rule by ID
Overview
useRecurrence fetches a single recurrence rule by its ID. It calls GET {apiUrl}/recurrence/{ruleId}.
import { useRecurrence } from '@roomkit/react';Usage
function RecurrenceDetail({ ruleId }: { ruleId: string }) {
const { data, isLoading, error } = useRecurrence({ ruleId });
if (isLoading) return <div>Loading...</div>;
if (!data) return <div>Rule not found</div>;
return (
<div>
<p>Frequency: {data.frequency}</p>
<p>Days: {data.daysOfWeek.join(', ')}</p>
<p>Series: {data.seriesStartsAt} — {data.seriesEndsAt}</p>
{data.calendarWeeks && (
<p>Calendar weeks: {data.calendarWeeks.join(', ')}</p>
)}
{data.exceptionDates.length > 0 && (
<p>Exceptions: {data.exceptionDates.length} dates excluded</p>
)}
</div>
);
}UseRecurrenceOptions
interface UseRecurrenceOptions {
ruleId: string;
enabled?: boolean;
onSuccess?: (data: RecurrenceRule) => void;
onError?: (error: Error) => void;
}| Option | Type | Required | Description |
|---|---|---|---|
ruleId | string | Yes | The recurrence rule ID to fetch |
enabled | boolean | No | Set to false to skip the request |
onSuccess | (data) => void | No | Called when the request succeeds |
onError | (error) => void | No | Called when the request fails |
Return Value
| Field | Type | Description |
|---|---|---|
data | RecurrenceRule | null | The fetched recurrence rule |
isLoading | boolean | true while the request is in flight |
error | Error | null | The error if the request failed |
refetch | () => Promise<void> | Manually re-fetch the data |
API Endpoint
GET {apiUrl}/recurrence/{ruleId}