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
| Param | Required | Type | Description |
|---|---|---|---|
resource | Required | string | Resource name |
params.id | Required | Identifier | Record ID |
Returns
Same shape as useGetLock:
| Field | Type | Description |
|---|---|---|
data | Lock | null | undefined | Current lock |
isLoading | boolean | true on initial load |
isPending | boolean | true while no data yet |
error | Error | null | Fetch error |
Notes
- Subscribes to
lock/<resource>/<id>usinguseSubscribe. useOnReconnectensures the query is re-fetched after a disconnect, recovering any lock state changes that occurred during the outage.<LockStatus>uses this hook internally.