My App
RoomKitFrontend

useBooking

Fetch a single booking by ID

Overview

useBooking fetches a single booking by its ID. It calls GET {apiUrl}/bookings/{bookingId}.

import { useBooking } from '@roomkit/react';

Usage

function BookingDetail({ bookingId }: { bookingId: string }) {
    const { data, isLoading, error, refetch } = useBooking({
        bookingId,
    });

    if (isLoading) return <div>Loading...</div>;
    if (error) return <div>Error: {error.message}</div>;
    if (!data) return <div>Not found</div>;

    return (
        <div>
            <h2>{data.title}</h2>
            <p>Status: {data.status}</p>
            <p>Room: {data.roomId}</p>
            <p>{data.startsAt} — {data.endsAt}</p>
        </div>
    );
}

UseBookingOptions

interface UseBookingOptions {
    bookingId: string;
    enabled?: boolean;
    onSuccess?: (data: Booking) => void;
    onError?: (error: Error) => void;
}
OptionTypeRequiredDescription
bookingIdstringYesThe booking ID to fetch
enabledbooleanNoSet to false to skip the request (default: true)
onSuccess(data) => voidNoCalled when the request succeeds
onError(error) => voidNoCalled when the request fails

Return Value

FieldTypeDescription
dataBooking | nullThe fetched booking
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}/bookings/{bookingId}

On this page