useUnlock

useUnlock returns an unlock function for releasing a record lock.

Usage

import { useUnlock } from "@/components/realtime";
 
function UnlockButton({ resource, id }: { resource: string; id: number }) {
  const { unlock, isLoading, error } = useUnlock();
 
  return (
    <button onClick={() => unlock(resource, { id })} disabled={isLoading}>
      Release lock
    </button>
  );
}

Params

None.

Returns

FieldTypeDescription
unlock(resource, params) => Promise<Lock>Releases a lock
isLoadingbooleantrue while the call is in flight or identity is loading
errorError | nullThe last error

unlock signature

unlock(
  resource: string,
  params: { id: Identifier; identity?: Identifier; meta?: Record<string, unknown> }
): Promise<Lock>

Notes

  • If identity is omitted, falls back to useGetIdentity(). If no identity is available, the call throws.
  • Throws if no lock exists for the record or if the caller's identity does not match the lock holder.
  • useLockOnMount calls useUnlock automatically on component unmount — use it instead when you want lock-cleanup handled for you.