butr
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}
>
CallbackSignatureFires when
onConnect(wallet: ConnectedWallet) => voida wallet connects successfully
onConnectError(error: ConnectionError, connectorId: string) => voida connect attempt fails
onHydrated(outcome: HydrationOutcome) => voidonce, after the mount-time restore pass
onDisconnect(chainPlatform: ChainPlatform) => voida wallet disconnects
onReset() => void | Promise<void>all wallets are reset (clear auth tokens here)
onSlowConnect(connectorId: string) => voida connect exceeds slowConnectThresholdMs
onStorageError(error: unknown, context: string) => voida persistence write fails

Notes

  • onConnectError receives the normalised ConnectionError, so you branch on error.kind.
  • onHydrated is the only place to learn which stored wallets came back — see hydration.
  • onSlowConnect fires at most once per attempt, and only if the connect hasn't resolved or rejected by the threshold (default 5000 ms). Useful for a "still trying — check your wallet" hint or a slow-path metric.
  • onStorageError is the only signal for otherwise-silent persistence failures. Default with no callback is console.warn. See persistence.
  • onReset may 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).

On this page