Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/When does hub-react’s usePublicParty return undefined?Forum ↗

When does hub-react’s usePublicParty return undefined?

App Development4 posts174 views1 likesLast activity Feb 2022
CO
cocreatureOP
Feb 2022

The type of @daml/hub-reacts usePublicParty function returns string | undefined. I’m not quite clear on when it will return undefined and the docs aren’t super helpful either.

AL
Alex_Matson
Feb 2022

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)

CO
cocreature
Feb 2022

Thank you that makes sense!

AL
Alex_Matson
Feb 2022

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} ... />
← Back to Discussions