useGetLocks

useGetLocks fetches all current locks for a resource. It is a one-time query — use useGetLocksLive for a live view.

Usage

import { useGetLocks } from "@/components/realtime";
 
function LockedRecordsList() {
  const { data: locks, isPending } = useGetLocks("posts");
 
  if (isPending) return <p>Loading…</p>;
  return (
    <ul>
      {locks?.map((lock) => (
        <li key={String(lock.recordId)}>
          Record {String(lock.recordId)} locked by {String(lock.identity)}
        </li>
      ))}
    </ul>
  );
}

Params

ParamRequiredTypeDescription
resourceRequiredstringResource name

Returns

FieldTypeDescription
dataLock[] | undefinedAll locks for the resource (undefined while loading)
isLoadingbooleantrue on initial load
isPendingbooleantrue while there is no data yet
errorError | nullFetch error

Notes

  • Backed by TanStack Query with key [resource, "locks"].
  • For a live view that updates when locks change, use useGetLocksLive.