R
fn

useTabLeader

v0.0.13testeddemo

Elects a single leader tab using the Web Locks API. Only one tab at a time holds the lock for a given key. When the leader tab closes or the scope is disposed, another tab automatically becomes the leader.

Example

ts
const { isLeader } = useTabLeader('payment-polling');

watchEffect(() => {
  if (isLeader.value) {
    // Only this tab performs polling
    startPolling();
  } else {
    stopPolling();
  }
});

Demo

Loading demo…

Signature

ts
export function useTabLeader(key: string, options: UseTabLeaderOptions ={ ... }

Parameters

ParameterTypeDescription
keystringA unique lock name identifying the leader group
options?UseTabLeaderOptionsOptions

Returns

UseTabLeaderReturnLeader state and controls