useAnimate() is a React hook that provides imperative animation control with automatic cleanup. It returns a ref (scope) and an animate function that can target elements within that scope.
Signature
Return Value
A React ref object to attach to your container element. All animations will be scoped to this element and its descendants.
Scoped animation function. Works like
animate() but targets elements within the scope.Supports all the same overloads:animate(element, keyframes, options)animate(selector, keyframes, options)- selector is scoped to the refanimate(sequence, options)animate(value, keyframes, options)
Automatic Cleanup
All animations are automatically stopped when the component unmounts, preventing memory leaks and warnings.Examples
Basic Usage
Animate Child Elements
Animation Sequences
Parallel Animations
Stagger Children
Complex Sequence
Animate on Interaction
Control Playback
Animate Multiple Elements
Integration with State
Custom Animation Hook
Active Animations
Track currently running animations:Type Definitions
Comparison with AnimationControls
useAnimate:
- Works with regular HTML elements
- Scoped CSS selectors
- Cleaner syntax for sequences
- Automatic cleanup
- Better TypeScript support
See Also
- animate() - Imperative animation function
- stagger() - Stagger animation delays
- AnimationControls - Legacy alternative