fn
broadcastedRef
v0.0.13testeddemoCreates a custom ref that syncs its value across browser tabs via the BroadcastChannel API
Examples
ts
const count = broadcastedRef('counter', 0);ts
const state = broadcastedRef('payment-status', { status: 'pending' });Demo
Loading demo…
Signature
ts
export function broadcastedRef<T>(key: string, initialValue: T, options: BroadcastedRefOptions ={ ... }Type Parameters
TParameters
| Parameter | Type | Description |
|---|---|---|
key | string | The channel key to use for broadcasting |
initialValue | T | The initial value of the ref |
options? | BroadcastedRefOptions | Options |
Returns
Ref<T, T>A custom ref that broadcasts value changes across tabs