Skip to main content
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 value
  • config (optional) - Configuration options for the animated value
    • useNativeDriver?: boolean - Whether to use the native driver for animations

Returns

An Animated.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

Use useAnimatedValue 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 useRef to store the Animated.Value instance
  • 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: true when possible for better performance
  • Native driver supports: transform and opacity
  • Native driver does NOT support: layout properties (width, height, etc.) and backgroundColor
  • Animations run on the native thread, avoiding JavaScript thread blocking

See Also