Skip to main content
useMoonPay() returns the SDK client made available by <MoonPayProvider>. Call it from any function component below the provider to access integration methods.
ConnectScreen.tsx

Return value

useMoonPay() returns the client plus helpers for supplying the session token after mount. The client exposes every integration method — see the MoonPayProvider reference for the full list.

initialize()

Set the session token after the provider has mounted. Use this when you don’t have the token at mount time: mount <MoonPayProvider> without the sessionToken prop, then call initialize() once your server returns the token.
initialize() updates the provider’s state, so the client that carries the new token is available on the next render — not synchronously within the same call. Gate your flow on isInitialized (or read client again after the re-render) instead of reusing a client reference captured before initialize(). Call initialize() again to replace the token — for example, after a refresh or when switching accounts. Replacing the token clears any credentials cached from the previous session, so call client.getConnection() again to re-establish the customer’s connection.

isInitialized

true once a session token is available — set either through the sessionToken prop or a call to initialize(). Use it to defer connection calls until the SDK has a token; calling a connection method beforehand returns an err() result.

Errors

useMoonPay() throws if called outside a <MoonPayProvider>:
Mount the provider higher in the tree, or call the hook from a child of the provider.