Updating useSharedValueEffect
callback
#1020
Unanswered
timoisalive
asked this question in
Q&A
Replies: 2 comments 1 reply
-
I solved the issue with const derivedValue = useDerivedValue(() => {
return sharedValue.value + stateValue;
}, [sharedValue, stateValue]);
useSharedValueEffect(() => {
skiaValue.current = derivedValue.value;
}, derivedValue); |
Beta Was this translation helpful? Give feedback.
0 replies
-
The most performance sensitive way to go about it here is to simply have a useEffect hook with stateValue as a dependency and then run the same callback there. We could support the dependency array you suggested but it would need a bit of thinking on our side. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using the
react-native-gesture-handler
anduseSharedValueEffect
to drive my interaction and Skia animation. However, I have a problem, that the callback function inuseSharedValueEffect
is not up-to-date with my state.The
stateValue
never changes inside the callback, and hence has no effect in the above example.Is there a way to somehow refresh the callback? I would first try something like:
but I see it only takes shared values as dependencies.
I could make the
stateValue
a shared value, but in my real project it wouldn't make sense to change the state into a shared value.Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions