useGetLockLive

useGetLockLive fetches the current lock for a single record and automatically re-fetches it whenever a locked or unlocked event arrives on lock/<resource>/<id>, or when the transport reconnects.

Usage

import { useGetLockLive } from "@/components/realtime";
 
function LiveLockBadge({ resource, id }: { resource: string; id: number }) {
  const { data: lock, isPending } = useGetLockLive(resource, { id });
 
  if (isPending) return null;
  if (lock) return <span>Locked by {String(lock.identity)}</span>;
  return <span>Available</span>;
}

Params

ParamRequiredTypeDescription
resourceRequiredstringResource name
params.idRequiredIdentifierRecord ID

Returns

Same shape as useGetLock:

FieldTypeDescription
dataLock | null | undefinedCurrent lock
isLoadingbooleantrue on initial load
isPendingbooleantrue while no data yet
errorError | nullFetch error

Notes

  • Subscribes to lock/<resource>/<id> using useSubscribe.
  • useOnReconnect ensures the query is re-fetched after a disconnect, recovering any lock state changes that occurred during the outage.
  • <LockStatus> uses this hook internally.