Skip to main content

Function: useSyncStatus()

function useSyncStatus(stackName?): Record<string, SyncStatus>;

Defined in: react/src/hooks/sync.ts:30

Subscribes to replication state for one stack, or for all of them.

Reads the state DocStack's sync layer keeps rather than tracking replication in the component: lastConvergedAt is the honest "last synced" value - the moment a cycle finished with nothing left to send - while lastActiveAt only says documents moved.

The subscription is on the stacks, not on the replication handles, so it survives a StackSyncHandle.restart (a refreshed credential, say) and works whether it mounts before or after sync() was called.

Parameters

ParameterTypeDescription
stackName?stringNarrow to a single stack. Omit for every open stack.

Returns

Record<string, SyncStatus>

A map of stack name to SyncStatus; empty for stacks that have never synced.

Example

const SyncBadge = ({ stack }: { stack: string }) => {
const status = useSyncStatus(stack)[stack];
if (!status) return <span>Not syncing</span>;
if (status.state === 'error') return <span>Offline - retrying</span>;
return <span>Synced {status.lastConvergedAt ? timeAgo(status.lastConvergedAt) : 'never'}</span>;
};