Skip to main content
Version: next

Interpolation

Interpolation maps one range of values to another. In animation it's commonly used to convert a driver (like 0 → 200) into a different output (opacity, color, degrees).

note

Call .to(inRange, outRange) on an AnimateValue. The result stays reactive as the source value changes.

Basic usage

const [x, setX] = useValue(0);

<animate.div
style={{
translateX: x,
background: x.to([0, 200], ['#60a5fa', '#818cf8']),
}}
/>
Preview

Parameters

NameTypeDescription
inRangenumber[]The input range (must be ascending). At least 2 values.
outRange(number | string)[]Outputs mapped to each inRange entry. Numbers, units, functions, or colors.
configExtrapolateConfig (optional)Extrapolation and easing.

ExtrapolateConfig

PropertyTypeDefaultDescription
extrapolateclamp | extend | identityextendGlobal fallback for left/right
extrapolateLeftclamp | extend | identityInheritsInput below first inRange
extrapolateRightclamp | extend | identityInheritsInput above last inRange
easing(t: number) => numberundefinedEasing on normalized t

Supported output formats

  1. Numbersvalue.to([0, 1], [10, 20]) → 15
  2. Strings with unitsvalue.to([0, 1], ['10px', '20px'])
  3. CSS functionsvalue.to([0, 1], ['rotate(0deg)', 'rotate(180deg)'])
  4. Colors — named, HEX, RGBA, HSL