I know in class components we use addListener in this way:
const Animated.Value= new Animated.Value(0);
Animated.Value.addListener((value)=>this.value=value;)
I wondering how should i convert Animated.Value.addListener in functional components?and second question: should i put addListener in useEffect hook?
In my case, I did as below
import React, { useRef, useEffect } from "react";
const AnimationBox = (props) => {
const pan: any = useRef(new Animated.ValueXY(props.pan)).current;
useEffect(() => {
pan.addListener((value) => {
console.log(value);
});
return () => {
pan.removeAllListeners();
};
}, []):
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With