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

Time:09-20

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?

CodePudding user response:

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

  • Related