useFlightEvents provides access to the live flight event log. It hydrates from GET /api/flight-events on mount, then subscribes to flight:event Socket.io events to append new events as they arrive. Comment mutations (add, edit, delete) use optimistic updates.
Import
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
options.flightId | string | number | null | Filter events to a specific flight. Defaults to the current active flight. |
options.categories | EventCategory[] | Filter events by category. If omitted, all categories are returned. |
Return value
| Field | Type | Description |
|---|---|---|
events | FlightLogEvent[] | Ordered array of flight events (filtered if categories was provided) |
isTracking | boolean | Whether a flight is currently active |
isLoading | boolean | True during the initial REST fetch |
addComment | (message: string) => void | Add a pilot comment event to the current flight |
editComment | (id: string, message: string) => void | Edit an existing comment (optimistic update) |
deleteComment | (id: string) => void | Delete a comment (optimistic update) |
FlightLogEvent
EventCategory enum
INFO category. Pilot comments are stored as SYSTEM events with a distinct source flag.
Usage
Filtering by category
Editing and deleting comments
Notes
- New events arriving via Socket.io are appended to the end of the
eventsarray without invalidating or refetching the full query. addCommentdoes not use an optimistic update — the new comment event arrives via theflight:eventSocket.io broadcast and is appended automatically.editCommentanddeleteCommentapply optimistic updates immediately and roll back on API error.- The
staleTime: Infinitysetting means events are never automatically re-fetched in the background.