fn
useMath
v0.0.15testeddemoReactive wrapper over any callable `Math.<key>` method. Each argument may be a plain value, a ref or a getter; the result recomputes lazily whenever a reactive input changes.
Examples
ts
const a = ref(2);
const b = ref(8);
const max = useMath('max', a, b); // ComputedRef<number> -> 8ts
// getters and plain values mix freely
const value = ref(-4.7);
const rounded = useMath('round', value); // 5 -> -5
const absVal = useMath('abs', () => value.value); // 4.7ts
// variadic methods
const sides = ref([3, 4]);
const dist = useMath('hypot', () => sides.value[0], () => sides.value[1]); // 5Demo
Loading demo…
Signature
ts
export function useMath<K extends UseMathKey>(
key: K,
...args: UseMathArgs<K>
): UseMathReturn<K>{ ... }Type Parameters
Kextends UseMathKeyParameters
| Parameter | Type | Description |
|---|---|---|
key | K | The name of the `Math` method to wrap (e.g. `'max'`, `'round'`, `'hypot'`). |
args? | UseMathArgs<K> | The reactive arguments forwarded to the method. |
Returns
UseMathReturn<K>A computed ref holding the method's result.