React-native Animated api : undefined is not a constructor (evaluating 'new _reactNative.Animated.value(0)')

Viewed 724

I was following the code from react native documentation for using Animated API here

I got an error while using this line

const scrollY = useRef( new Animated.value(0)).current;

ERROR : TypeError: undefined is not a constructor (evaluating 'new _reactNative.Animated.value(0)')

I have imported Animated from

import { Animated } from "react-native";

I don't know what I have done wrong, I am using the same code from the documentation

2 Answers

It's:

const scrollY = useRef( new Animated.Value(0)).current;

Not

const scrollY = useRef( new Animated.value(0)).current;

From v to uppercase V

I had the same issue, and I found a solution. Try the following code:

Animated.timing(scrollY,{
  toValue:
  duration:
  useNativeDriver: false
})
Related