useGetOneLive
useGetOneLive is a drop-in replacement for useGetOne that subscribes to the individual record topic and re-fetches whenever an event arrives for that record or the transport reconnects.
Usage
import { useGetOneLive } from "@/components/realtime";
function PostDetail({ id }: { id: number }) {
const { data, isPending, error } = useGetOneLive("posts", { id });
if (isPending) return <p>Loading…</p>;
if (error) return <p>Error: {error.message}</p>;
return <h1>{data?.title}</h1>;
}Params
| Param | Required | Type | Description |
|---|---|---|---|
resource | Required | string | Resource name |
params | Required | GetOneParams | Must include id |
options | Optional | UseQueryOptions | TanStack Query options forwarded to useGetOne |
Returns
Identical to useGetOne.
Notes
- Subscribes to
resource/<name>/<id>and invalidates all queries for the resource on any event. useOnReconnectis called internally.- Use
<EditLive>or<ShowLive>for page-level record updates without dealing with this hook directly.