Skip to main content

Overview

useEvent reads the event loaded by EventProvider from context, returning the event plus bound actions (updateEvent, deleteEvent, cancelEvent, setRsvp, withdrawRsvp). useEventData is the underlying hook the provider uses — call it directly when you want the same managed state without the provider/context.

useEvent

Call inside a descendant of EventProvider.
useEvent returns a Partial<UseEventDataValues> (empty object outside a provider).

useEventData

Manage an event without the provider. Pass either a pre-fetched event or an eventId to fetch.

Parameters

Event
A pre-fetched event. Use this or eventId.
string
An event ID to fetch. Use this or event.
EventIncludeParam
Associations to expand when fetching by eventId, as a single value or an array: "user", "space", "files", "userRsvp".

Returns (both hooks)

Event | null | undefined
The event. undefined while loading, null if not found or inaccessible — also after the event is deleted, and after a cancel or withdraw answers with a short body because the user can no longer see it. Such an event stays null for that eventId: the hook doesn’t fetch it again.
React.Dispatch
Set the event state directly (optimistic updates).
(changes: Omit<UpdateEventProps, "eventId">) => Promise<Event | undefined>
Update mutable fields, the cover, images and files. Takes the changes alone, e.g. updateEvent({ capacity: 150 }): the fields of useUpdateEvent without eventId. Hosts who are active members of the event’s space.
() => Promise<void>
Delete the event (its owner, or the space’s admins and moderators). Sets event to null.
() => Promise<CancelEventResponse | undefined>
Cancel the event (its owner, or the space’s admins and moderators). Resolves with the event, or with { id, status: "cancelled" } when the user can’t see it, which sets event to null.
(status: RsvpStatus) => Promise<Event | undefined>
Set/change the caller’s RSVP.
() => Promise<WithdrawRsvpResponse | undefined>
Withdraw the caller’s RSVP. Resolves with the event, or with { id, userRsvp: null } when the user can no longer see it, which sets event to null.
Every full-event response (update, cancel, RSVP, withdraw) is merged onto the loaded event, so the space and files it was fetched with stay, and the result is kept for when the hook comes back to the same eventId.

See Also