-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loading: false, error: undefined, value: undefined when using useDocument #17
Comments
@fastest963 I'm struggling to reproduce this.
When a document reference is specified then the state is reset and My test case for this is as follows, which tests by cycling through two different document references and a null reference:
|
@chrisbianca interesting. I assume this is some sort of race condition then. If I add a breakpoint and am able to step through the stack, is there anything that would help you identify how it's happening? |
So I've just been doing some digging, and it looks like there is an extra render cycle which is causing what you're seeing. In my example above, I've added some logging, which produces the following when switching from
As I understand it, the reason for this is that toggling the button calls In essence this shouldn't cause an issue, but it's not ideal. I'll do some reading / digging to see if there's a better way to workaround this sort of issue when chaining hooks together. |
@chrisbianca I might have found a solution for this issue I don't think it is correct to call setValue in the hooks when no value is present, a reset sounds more logical and solves the loading state switching to loaded. |
Hey all. I'd like to reopen this issue as it is still causing some grief for me. The basic flow is: const {userId} = useContext(UserContext);
const [profile, loading, error] = useDocumentData(userId ? firestore().collection('profiles').doc(userId) : null);
console.log(userId, profile, loading, error); Assuming the
The problem is number 2. causes issues downstream, because I might want to take a case where the |
I also seem to be getting the same issue described by @royletron uid is initially undefined, and a value is then loaded/set via context
My current solution is the following Passing any reference seems to set the loading state correctly. Not sure if i am potentially causing other issues but seems to work for now |
Thanks to #10, we are now able to do:
The problem is that if the user exists then a document reference is sent but
useDocumentOnce
returns{ loading: false, error: undefined, value: undefined }
. I was under the assumption that once loading is false, the value should be the DocumentSnapshot. It looks like this was caused by 01e8616 because callingsetValue(undefined)
ends up setting the loading value to false.I'm not sure if the best fix is to change the
useLoadingValue
's reducer to check the value before setting loading to false or if instead it shouldn't callsetValue(undefined)
if the value is already undefined.The text was updated successfully, but these errors were encountered: