Files
fuel-price/.agents/skills/vueuse-functions/references/useClamp.md
Ovidiu U 4a3ce4cc1d
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
docs: add advanced skills for Vitest, Pinia, and Vue built-ins
Add comprehensive reference documentation for:
- Vitest: environments, projects/workspaces, type testing, vi utilities
- Pinia: HMR, Nuxt integration, SSR setup
- Vue: built-in components (Transition, Teleport, Suspense, KeepAlive) and advanced directives
2026-04-11 16:28:36 +01:00

86 lines
1.7 KiB
Markdown

---
category: '@Math'
---
# useClamp
Reactively clamp a value between two other values.
## Usage
```ts
import { useClamp } from '@vueuse/math'
const min = shallowRef(0)
const max = shallowRef(10)
const value = useClamp(0, min, max)
```
### Writable Ref
When you pass a mutable `ref`, the returned value is a **writable computed** that clamps values when setting:
```ts
import { useClamp } from '@vueuse/math'
const number = shallowRef(0)
const clamped = useClamp(number, 0, 10)
clamped.value = 15 // clamped.value will be 10
clamped.value = -5 // clamped.value will be 0
```
### Read-only Mode
When you pass a getter function or readonly ref, the returned value is a read-only computed:
```ts
import { useClamp } from '@vueuse/math'
const value = ref(5)
const clamped = useClamp(() => value.value * 2, 0, 10)
// clamped.value is computed from the getter
```
### Reactive Bounds
All arguments (value, min, max) can be reactive:
```ts
import { useClamp } from '@vueuse/math'
const value = shallowRef(5)
const min = shallowRef(0)
const max = shallowRef(10)
const clamped = useClamp(value, min, max)
max.value = 3 // clamped.value automatically becomes 3
```
## Type Declarations
```ts
/**
* Reactively clamp a value between two other values.
*
* @see https://vueuse.org/useClamp
* @param value number
* @param min
* @param max
*
* @__NO_SIDE_EFFECTS__
*/
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>
```