2) when I use a context with 2 props: theme and lang, whenever I change several times the same prop (ie. lang) only the "lang consumer" rerender as expected.
When I update one prop (ie. lang) then the other prop (ie. theme) then the app rerender both props consumers, opposite of what I was expecting: lang consumer shouldn't rerender on theme change...
If I "follow" updating theme value, only theme consumer rerender, but each time I modify "the other prop", both (all) consumers rerender...
Below code sample:
Developer: javascript, typescript, React, ... I love to discover new things, exploring code of libraries and understand how things work.
Fan of creative hobbies :)
Indeed, it's really strange. I have tried on snack.expo.dev/ and it has a weird behavior. If I chose the Web device it works fine but not on Android and iOS.
It seems to be due to the fact of always calling setSelectedValue in useContextSelector. Because if I condition it it's working.
I will try to deep dive more and will come back to you ;)
2) when I use a context with 2 props: theme and lang, whenever I change several times the same prop (ie. lang) only the "lang consumer" rerender as expected.
When I update one prop (ie. lang) then the other prop (ie. theme) then the app rerender both props consumers, opposite of what I was expecting: lang consumer shouldn't rerender on theme change...
If I "follow" updating theme value, only theme consumer rerender, but each time I modify "the other prop", both (all) consumers rerender...
Below code sample:
Indeed, it's really strange. I have tried on snack.expo.dev/ and it has a weird behavior. If I chose the
Web
device it works fine but not onAndroid
andiOS
.It seems to be due to the fact of always calling
setSelectedValue
inuseContextSelector
. Because if I condition it it's working.I will try to deep dive more and will come back to you ;)
Você pode estar fazendo assim para resolver esse problema: