Zustand is returning the initial value, not the value after fetch in UseEffect. Why? #2456
Unanswered
ioiofadhil
asked this question in
Q&A
Replies: 2 comments
-
It's a correct behavior with React and has nothing to do with Zustand. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@ioiofadhil that's the expected behavior talking about stale closures |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. Thanks for the this state-management. Super friendly.
I tried to store my data result from fetch in the store like this :
But when i call inside component like this :
the first console.log returning the initial value, which is a
false
. But the second one returning after the changes. Why is this happening? I really prefer the first console log write because for me, the style looks more cleaner. Appreciate any help!! Thanks before!Beta Was this translation helpful? Give feedback.
All reactions