My App
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;
}
OptionTypeRequiredDescription
ruleIdstringYesThe recurrence rule ID to fetch
enabledbooleanNoSet to false to skip the request
onSuccess(data) => voidNoCalled when the request succeeds
onError(error) => voidNoCalled when the request fails

Return Value

FieldTypeDescription
dataRecurrenceRule | nullThe fetched recurrence rule
isLoadingbooleantrue while the request is in flight
errorError | nullThe error if the request failed
refetch() => Promise<void>Manually re-fetch the data

API Endpoint

GET {apiUrl}/recurrence/{ruleId}

On this page