fn
useTransition
v0.0.15testeddemoReactively transition between numeric values (or numeric arrays) over a duration with configurable easing. Wraps a single, paused `requestAnimationFrame` loop that only runs while a transition is in flight, so it is cheaper than re-creating an RAF loop per change. SSR-safe: without a `window` the output tracks the source synchronously.
Examples
ts
const progress = ref(0);
const output = useTransition(progress, {
duration: 500,
transition: TransitionPresets.easeOutCubic,
});ts
// Transition a tuple (e.g. an RGB color)
const color = ref([0, 0, 0]);
const animated = useTransition(color, { duration: 1000 });Demo
Loading demo…
Signature
ts
export function useTransition<T extends TransitionValue>(
source: MaybeRefOrGetter<T>,
options: UseTransitionOptions & ConfigurableWindow ={ ... }Type Parameters
Textends TransitionValueParameters
| Parameter | Type | Description |
|---|---|---|
source | MaybeRefOrGetter<T> | The reactive source value (number or number[]) |
options? | any | Transition options |
Returns
Readonly<Ref<T, T>>A readonly ref of the transitioned value