R
fn

useSyncRefs

v0.0.1testeddemo

Syncs the value of a source ref with multiple target refs

Examples

ts
const source = ref(0);
const target1 = ref(0);
const target2 = ref(0);
useSyncRefs(source, [target1, target2]);
ts
const source = ref(0);
const target1 = ref(0);
useSyncRefs(source, target1, { immediate: true });

Demo

Loading demo…

Signature

ts
export function useSyncRefs<T = unknown>(
  source: WatchSource<T>,
  targets: Ref<T> | Array<Ref<T>>,
  watchOptions: WatchOptions ={ ... }

Type Parameters

T= unknown

Parameters

ParameterTypeDescription
sourceWatchSource<T>Source ref to sync
targetsRef<T, T> | Ref<T, T>[]Target refs to sync
watchOptions?WatchOptions<boolean>Watch options

Returns

import("vue").WatchHandleWatch stop handle