When and how to use dependencies of useAnimatedStyle #4409
-
I think I have read the documentation about this a million times, but I can't bring myself to understanding it 😅 When is it appropriate to use the different options of the dependencies in
Let's say I've got this component: function Box() {
const opacity = useSharedValue(0);
const animatedStyles = useAnimatedStyle(() => ({
opacity: opacity.value,
}));
const onClick = useCallback(() => {
opacity.value = withTiming(1, { duration: 200 });
}, [opacity]);
return (
<>
<Animated.View style={[styles.box, animatedStyles]} />
<Button onPress={onClick} title="Move" />
</>
);
} So, the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I believe you should only use that dependency array if your animated style worklet function depends on values from the JS thread. You do not need to include shared values in the dependency array. For example:
|
Beta Was this translation helpful? Give feedback.
I believe you should only use that dependency array if your animated style worklet function depends on values from the JS thread. You do not need to include shared values in the dependency array. For example: