Guides
Lifecycle callbacks
onConnect, onConnectError, onHydrated, onDisconnect, onReset, onSlowConnect, onStorageError.
WalletManagerConfig (and the matching WalletManagerProvider props)
expose lifecycle callbacks. They exist so you wire observability and side
effects in one place instead of wrapping every connect call in
try/catch.
import { WalletManagerProvider } from "@usebutr/react";
import { autoDiscovery } from "@usebutr/wallets";
const discovery = autoDiscovery();
<WalletManagerProvider
discovery={discovery}
onConnect={(wallet) => track("wallet_connected", { id: wallet.connector.id })}
onConnectError={(error, connectorId) => reportToSentry(error, { connectorId })}
onHydrated={(outcome) => track("hydrated", outcome)}
onDisconnect={(platform) => track("wallet_disconnected", { platform })}
onReset={() => clearAuthTokens()}
onSlowConnect={(connectorId) => showHint(`${connectorId} is taking a while…`)}
onStorageError={(error, context) => reportToSentry(error, { context })}
slowConnectThresholdMs={8000}
>| Callback | Signature | Fires when |
|---|---|---|
onConnect | (wallet: ConnectedWallet) => void | a wallet connects successfully |
onConnectError | (error: ConnectionError, connectorId: string) => void | a connect attempt fails |
onHydrated | (outcome: HydrationOutcome) => void | once, after the mount-time restore pass |
onDisconnect | (chainPlatform: ChainPlatform) => void | a wallet disconnects |
onReset | () => void | Promise<void> | all wallets are reset (clear auth tokens here) |
onSlowConnect | (connectorId: string) => void | a connect exceeds slowConnectThresholdMs |
onStorageError | (error: unknown, context: string) => void | a persistence write fails |
Notes
onConnectErrorreceives the normalisedConnectionError, so you branch onerror.kind.onHydratedis the only place to learn which stored wallets came back — see hydration.onSlowConnectfires at most once per attempt, and only if the connect hasn't resolved or rejected by the threshold (default5000ms). Useful for a "still trying — check your wallet" hint or a slow-path metric.onStorageErroris the only signal for otherwise-silent persistence failures. Default with no callback isconsole.warn. See persistence.onResetmay return a promise — a good place to clear server-side sessions or auth tokens.
Source: packages/core/src/types/wallet.ts (WalletManagerConfig),
packages/react/src/context.tsx (WalletManagerProviderProps).