The type of @daml/hub-react
s usePublicParty
function returns string | undefined
. I’m not quite clear on when it will return undefined
and the docs aren’t super helpful either.
The value is initialized to undefined
, and the hook will return undefined
in 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)
Thank you that makes sense!
I should note then that the undefined
status 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} ... />
1 Like