useAnimationFrame
Runs a callback on every requestAnimationFrame tick with delta time tracking, FPS limiting, and playback controls.
Loading preview...
The useAnimationFrame hook runs a callback on every requestAnimationFrame tick, providing frame timing metadata (timestamp, deltaTime, elapsedTime), optional FPS throttling, and imperative playback controls.
Installation
Usage
Examples
FPS Limiting
Use fpsLimit to cap how often the callback runs per second while keeping smooth frame pacing.
Manual Start
Set immediate: false to keep the loop paused on mount and start it on user interaction.
API Reference
AnimationFrameInfo
Timing metadata passed to the callback on each animation frame.
Property
Specification
timestampnumber
High-resolution timestamp passed by
requestAnimationFramedeltaTimenumber
Time elapsed in milliseconds since the previous frame
elapsedTimenumber
Total time elapsed in milliseconds since the loop started
UseAnimationFrameOptions
Configuration options for the animation loop.
Property
Specification
immediate?uniondefault:true
Start the animation loop immediately on mount
Full Signature
fpsLimit?number
Optional maximum frames per second limit
Full Signature
UseAnimationFrameControls
Playback controls and state returned by the hook.
Property
Specification
startfunction
Starts the animation frame loop
Full Signature
stopfunction
Stops the animation frame loop and resets timing counters
Full Signature
togglefunction
Toggles the animation frame loop between active and stopped states
Full Signature
isActiveunion
Whether the animation frame loop is currently running
Full Signature