useClamp ​
Reactively clamp a value between two other values.
Demo ​
min: max: value:0
Usage ​
ts
import { useClamp } from '@vueuse/math'
const min = ref(0)
const max = ref(10)
const value = useClamp(0, min, max)
You can also pass a ref
and the returned computed
will be updated when the source ref changes:
ts
import { useClamp } from '@vueuse/math'
const number = ref(0)
const clamped = useClamp(number, 0, 10)
Type Declarations ​
typescript
export declare function useClamp(
value: ReadonlyRefOrGetter<number>,
min: MaybeRefOrGetter<number>,
max: MaybeRefOrGetter<number>,
): ComputedRef<number>
export declare function useClamp(
value: MaybeRefOrGetter<number>,
min: MaybeRefOrGetter<number>,
max: MaybeRefOrGetter<number>,
): Ref<number>
Source ​
Contributors ​
Anthony Fu
Anthony Fu
ClemDee
Changelog ​
Pending for release...
59f75
- feat(toValue): deprecate toValue
from @vueuse/shared
in favor of Vue's nativev12.0.0-beta.1
on 11/21/2024v10.0.0-beta.5
on 4/13/2023cb644
- refactor!: remove isFunction
and isString
utilsv10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v9.13.0
on 2/18/2023