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

ParamRequiredTypeDescription
resourceRequiredstringResource name
paramsRequiredGetOneParamsMust include id
optionsOptionalUseQueryOptionsTanStack 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.
  • useOnReconnect is called internally.
  • Use <EditLive> or <ShowLive> for page-level record updates without dealing with this hook directly.