我一直在阅读重新激活 2 Hooks 的文档并在所有互联网上搜索更好解释的博客或任何代码,但找不到任何一个,任何人都可以解释并给出源代码示例。作为示例
const App = () => {
const [state, setState] = useState(0);
const sv = useSharedValue(0);
const handler = useAnimatedGestureHandler(
{
onEnd: (_) => {
sv.value = state;
},
},
dependencies
);
//...
return <></>;
};
但是当我尝试
const [test, setTest ] = useState(true);
const gestureHandler = useAnimatedGestureHandler({
onStart : (event,context)=>{
console.log("onstart");
setTest(true);
context.startX = X.value;
},
onActive : (event,context)=>{
console.log("onactive");
X.value = context.startX + event.translationX;
},
onEnd : (event,context)=>{
console.log("onEnd");
setTest(false);
}
},
[test]
)
我得到了错误
Tried to Synchronously call function (bound dispatchAction)
from different thread.