useAnimatedValue is a React hook that creates a persistent Animated.Value instance. The animated value is created only once and persists across component re-renders, making it ideal for animations in functional components.
Signature
Parameters
initialValue- The initial numeric value for the animated valueconfig(optional) - Configuration options for the animated valueuseNativeDriver?: boolean- Whether to use the native driver for animations
Returns
AnAnimated.Value instance that persists across re-renders.
Usage
Common Patterns
Fade Animation
Scale Animation
Slide Animation
Progress Bar
Rotate Animation
Color Animation
When to Use
UseuseAnimatedValue when you need:
- A single numeric animated value in a functional component
- To animate properties like opacity, scale, rotation, or position
- A persistent animation value that survives re-renders
Alternatives
- useAnimatedValueXY - For animating 2D positions (x, y coordinates)
- new Animated.Value() - Class component equivalent (requires manual ref management in functional components)
- Reanimated library - For more complex animations with better performance
Implementation Details
This hook:- Uses
useRefto store theAnimated.Valueinstance - Creates the animated value only once on first render
- Returns the same instance on subsequent re-renders
- The initial value is only used during the first render
Performance Tips
- Always use
useNativeDriver: truewhen possible for better performance - Native driver supports:
transformandopacity - Native driver does NOT support:
layoutproperties (width, height, etc.) andbackgroundColor - Animations run on the native thread, avoiding JavaScript thread blocking
See Also
- useAnimatedValueXY - Hook for 2D animated values
- Animated API - Complete animation API reference
- Animation Guide - Comprehensive guide to animations