Skip to content

How to compare shared value inside areEqualProps? #6221

Closed Answered by MatiPl01
VictorioMolina asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

In general, you shouldn't rely on the SharedValue read via the .value prop, so 3 and 4 are incorrect. Similarly, the first one proposed solution is incorrect, because lodash makes deep comparison of objects, so it will compare .value prop.

The correct solution is 2

Long explanation

Even though comparing .value from the JS thread is technically incorrect, in your case, all of listed proposed solution should work the same unless you pass a completely different SharedValue to your component, e.g. like this:

const progress1 = useSharedValue(0);
const progress2 = useSharedValue(0);

During the initial render:

<MyComponent animatedProgress={progress1} /> 

Some time later, when the compone…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by VictorioMolina
Comment options

You must be logged in to vote
1 reply
@MatiPl01
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants