R
fn

broadcastedRef

v0.0.13testeddemo

Creates 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

T

Parameters

ParameterTypeDescription
keystringThe channel key to use for broadcasting
initialValueTThe initial value of the ref
options?BroadcastedRefOptionsOptions

Returns

Ref<T, T>A custom ref that broadcasts value changes across tabs