我知道在类组件中,我们以这种方式使用addListener:
voucher
我想知道如何在功能组件中转换Animated.Value.addListener吗?第二个问题:我应该将addListener放在useEffect挂钩中吗?
答案 0 :(得分:1)
就我而言,我的操作如下
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();
};
}, []):
}