You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using managed state, if an error occurs in an async function for the first time, error is initially undefined while request.error immediately contains the expected error.
Upon calling the problematic async function again, they are both defined, and match. Is this expected behaviour or a bug?
Backstory: I had a bug in my server causing it to 500 on every request, and saw out that my frontend wasn't noticing the first server error properly, but was reacting to the second and subsequent. As a band-aid, I changed from checking error to request.error and things are working as expected. However, I don't understand why this band-aid was necessary, and expect others may run into the same situation.
OK, I couldn't find anything about this in text form (my preference), but after submitting this issue I finally watched the video tutorial for managed state which explained why I was getting stale values: request.error is a getter which will always pull from the current error ref, whereas plain old error can get stale between renders.
Can we update the README for managed state with a warning? I think because the provided example in the docs exposes error, with no mention of staleness, I just assumed that's what I should be using.
Describe the bug
When using managed state, if an error occurs in an async function for the first time,
error
is initially undefined whilerequest.error
immediately contains the expected error.Upon calling the problematic async function again, they are both defined, and match. Is this expected behaviour or a bug?
Backstory: I had a bug in my server causing it to 500 on every request, and saw out that my frontend wasn't noticing the first server error properly, but was reacting to the second and subsequent. As a band-aid, I changed from checking
error
torequest.error
and things are working as expected. However, I don't understand why this band-aid was necessary, and expect others may run into the same situation.I've created a trivial example on Codesandbox.
https://codesandbox.io/s/keen-cloud-m1x3k?file=/src/App.js
To Reproduce
Steps to reproduce the behavior:
error
is undefined whilerequest.error
is definedExpected behavior
They should both be defined the first time, right?
The text was updated successfully, but these errors were encountered: