Shouldn't we use Animated api in functional component without wrapping with useRef()?

Viewed 16

This is how Animated api is declared in class component,

const pan = new Animated.ValueXY();

Where as in functional components,

const pan = useRef(new Animated.ValueXY()).current;

Source: React-Native official documentation

Will there be any caveats if we use Animated api without wrapping with useRef?

1 Answers

Functional components will be called during every rendering. Without useRef. you will get a new pan everytime.

Related