Skip to content

Fix incorrect useAnimatedValue usage in Animated documentation #5263

Description

@devguilhermeholm

Description

The Animated documentation currently contains an incorrect code example that imports and uses useAnimatedValue from react-native.

The example fails at runtime because useAnimatedValue is not available from react-native in the version used by the documentation.

This PR fixes the example by replacing useAnimatedValue(0) with new Animated.Value(0) and removing useAnimatedValue from the imports.

What is the problem?

The example in the Animated documentation imports useAnimatedValue from react-native and uses it to initialize the animated value.

This results in a runtime error because useAnimatedValue is not available from react-native:

TypeError: (0, _reactNative.useAnimatedValue) is not a function

As a result, users following the official documentation are unable to run the example as provided.

How can we address it?

Replace useAnimatedValue(0) with new Animated.Value(0) and remove useAnimatedValue from the react-native imports.

No other changes to the example are required.

Why is it important?

The example is part of the official React Native documentation, so users may reasonably expect the code to work when copied directly into a project.

A runtime error in a basic Animated example can be particularly confusing for developers learning or getting started with React Native.

Who needs this?

This is relevant to developers using the React Native Animated API, especially developers learning React Native or following the official documentation examples.

When should this happen (use version numbers if needed)?

This should be fixed as soon as possible so that the Animated documentation provides a working example.

#5122

Activity

  1. Simek commented on Oct 6, 2026

    @Simek
    Collaborator

    Hey @devguilhermeholm, thanks for rising this problem, however this is not an issue with React Native itself, but with React Native Web, which is a separate framework/package.

    Lack of that hook should be reported and fixed in the React Native Web repository:

    I will update the example to disallow web platform for now, to avoid further confusion.

  2. devguilhermeholm commented on Oct 8, 2026

    @devguilhermeholm
    Author

    Thanks @Simek! I opened a PR in React Native Web adding the useAnimatedValue hook: necolas/react-native-web#2893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions