Overview
TheuseTime() hook returns a MotionValue that automatically updates with the elapsed time in milliseconds since the animation frame loop started. This is useful for creating time-based animations and effects.
Import
Usage
Return Value
A
MotionValue that updates every frame with the current time in milliseconds. The time represents elapsed time since the frameloop started, not absolute timestamp.Examples
Continuous Rotation
Create a continuously rotating element:Wave Animation
Create a wave effect using sine transformation:Multiple Synchronized Elements
Synchronize multiple elements with offset timing:Time-based Counter
Display elapsed seconds:Pulsating Effect
Create a scale pulse animation:Performance
The
useTime() hook updates every animation frame. When using it with useTransform(), Motion automatically optimizes updates to only occur when necessary.Best Practices
Combine with useTransform
Combine with useTransform
Use
useTransform() to derive animated values from time rather than using useEffect with state updates. This ensures smooth, performant animations.Avoid heavy computations
Avoid heavy computations
Keep transform functions lightweight. Heavy computations in transform callbacks can cause frame drops since they run every frame.
Share time values
Share time values
Implementation Details
- Uses
useMotionValue()internally to create the time value - Subscribes to the animation frame loop via
useAnimationFrame() - Automatically cleans up subscriptions when component unmounts
- Time value represents elapsed time, not absolute timestamp
- Frame updates are synchronized with browser’s requestAnimationFrame
Related
useTransform
Transform motion values
useMotionValue
Create motion values
MotionValue
MotionValue API reference
Performance Guide
Optimize animations