When does hub-react’s usePublicParty return undefined?
- cocreatureOP
The type of
@daml/hub-reactsusePublicPartyfunction returnsstring | undefined. I’m not quite clear on when it will returnundefinedand the docs aren’t super helpful either. - Alex_Matson
The value is initialized to
undefined, and the hook will returnundefinedin the interim period between when the context is initialized and the API request to get the default parties returns with the value (which should be fairly quick) - cocreature
Thank you that makes sense!
- Alex_Matson 1
I should note then that the
undefinedstatus can be used to indicate a loading state since the hook does not explicitly return status information on the API request.const publicParty = usePublicParty(); if (!publicParty) return <MyLoadingIndicator/>; // typescript infers publicParty to be a definitely defined "string" from this point onwards return <MyComponent publicParty={publicParty} ... />