Skip to content

useSpringMotion

@hua-labs/hua/motion

bash
npm install @hua-labs/hua
tsx
import { useSpringMotion } from "@hua-labs/hua/framework";

tsx
const spring = useSpringMotion({
  from: 0,
  to: 100,
  stiffness: 200,
  damping: 20,
});

return (
  <div
    ref={spring.ref}
    style={{
      ...spring.style,
      transform: `translateX(${spring.value}px)`,
    }}
  >
    Spring animated
  </div>
);

stiffness: 400, damping: 10

stiffness: 200, damping: 30

from*number-Starting value
to*number-Target value
massnumber1Virtual mass of the object
stiffnessnumber100Spring stiffness (higher = faster)
dampingnumber10Damping force (higher = less bounce)
restDeltanumber0.01Minimum distance to consider at rest
restSpeednumber0.01Minimum speed to consider at rest
enabledbooleantrueEnable/disable the spring
autoStartbooleanfalseStart animation automatically
onComplete() => void-Callback when spring reaches rest

refRefObject<T | null>Ref to attach to element
styleCSSPropertiesStyle with CSS vars (--motion-progress, --motion-value)
valuenumberCurrent spring value
velocitynumberCurrent velocity
isVisiblebooleanVisibility state
isAnimatingbooleanWhether spring is active
progressnumberAnimation progress (0-1)
start() => voidStart spring animation
stop() => voidStop animation
reset() => voidReset to initial state

tsx
// Bouncy (playful UI elements)
config: { stiffness: 400, damping: 10, mass: 1 }

// Smooth (elegant transitions)
config: { stiffness: 200, damping: 30, mass: 1 }

// Stiff (snappy responses)
config: { stiffness: 500, damping: 25, mass: 1 }

// Heavy (weighty feel)
config: { stiffness: 300, damping: 20, mass: 3 }