What is the correct usage of the useDerivedValue
hook?
#5808
-
Consider, please, the following code samples. Which variant is correct and why? First:
Second:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Even better: const [isVisible, setIsVisible] = useState(false);
const animatedStyles = useAnimatedStyle(() => ({
opacity: withTiming(isVisible ? 1 : 0),
})); Answering your question, this doesn't make much difference. The first approach might be slightly more performant, because less values are frequently updated ( Both approaches work, so use the one that you prefer. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply @MatiPl01. I also thought the first approach should be more performant, but I got ANR errors on Android. That's why I wonder. Here is the exact code that caused the error:
When I changed it to the following variant the error disappeared:
I had version 2.10.0 and [email protected]. |
Beta Was this translation helpful? Give feedback.
Can you upgrade reanimated to v3 if you use 2.10.0? v2 is no longer supported.
I've just tested on v3 and it works fine on both platforms.