useGetLock

useGetLock fetches the current lock for a single record. It is a one-time query — the result is not automatically refreshed when lock state changes. Use useGetLockLive for a live view.

Usage

import { useGetLock } from "@/components/realtime";
 
function LockInfo({ id }: { id: number }) {
  const { data: lock, isPending, error } = useGetLock("posts", { id });
 
  if (isPending) return <p>Checking lock…</p>;
  if (error) return <p>Error: {error.message}</p>;
  if (lock) return <p>Locked by {String(lock.identity)}</p>;
  return <p>Unlocked</p>;
}

Params

ParamRequiredTypeDescription
resourceRequiredstringResource name
params.idRequiredIdentifierRecord ID
params.metaOptionalRecord<string, unknown>Passed through to the LockProvider

Returns

FieldTypeDescription
dataLock | null | undefinedThe lock (null = no lock, undefined = not yet loaded)
isLoadingbooleantrue on initial load
isPendingbooleantrue while there is no data yet
errorError | nullFetch error

Notes

  • Backed by TanStack Query with key [resource, "lock", id].
  • Requires a LockProvider configured on the data provider. Throws at render time if no DataProvider is in context.