fn
useCached
v0.0.1testeddemoCaches the value of an external ref and updates it only when the value changes
Examples
ts
const externalValue = ref(0);
const cachedValue = useCached(externalValue);ts
const externalValue = ref(0);
const cachedValue = useCached(externalValue, (a, b) => a === b, { immediate: true });Demo
Loading demo…
Signature
ts
export function useCached<Value = unknown>(
externalValue: MaybeRefOrGetter<Value>,
comparator: Comparator<Value> = (a, b) => a === b,
watchOptions?: WatchOptions,
): Ref<Value>{ ... }Type Parameters
Value= unknownParameters
| Parameter | Type | Description |
|---|---|---|
externalValue | MaybeRefOrGetter<Value> | Ref to cache |
comparator? | Comparator<Value> | Comparator function to compare the values |
watchOptions? | WatchOptions<boolean> | undefined | Watch options |
Returns
Ref<Value, Value>Cached ref