@thru/react-sdk is the React layer on top of the Thru browser wallet. It wraps @thru/browser-sdk, exposes a client-side provider, and gives you hooks for wallet state, account selection, and the underlying Thru RPC client.
Install
Root export
Import everything from the package root:When to use it
Use@thru/react-sdk when you are building a React app that needs:
- Wallet connect and disconnect flows
- Selected-account and account-list state
- Access to the embedded browser wallet and Thru RPC client from React components
- A simple bridge between React UI and the lower-level browser SDK
- You are not using React: use
@thru/browser-sdkor@thru/embedded-provider - You want a prebuilt React control instead of hooks: use
@thru/react-ui
Main exports
ThruProvider
ThruProvider is the context provider for the package. It takes a config prop of type BrowserSDKConfig and must run in a client component.
The provider creates and owns a shared BrowserSDK instance, tracks connection state, surfaces the current accounts, and exposes the underlying Thru RPC client through context.
ThruProviderProps
ThruProviderProps requires children and a config value of type BrowserSDKConfig.
useWallet
useWallet() gives you the action-oriented API:
connect(options?)disconnect()mountInline(container)selectAccount(account)walletaccountsselectedAccountisConnectedisConnecting
useAccounts
useAccounts() returns the current accounts, selectedAccount, isConnected, and isConnecting state. It also accepts an optional onAccountSelect callback for reacting to selection changes.
| Option | Description |
|---|---|
onAccountSelect | Called when the selected account changes. |
useThru
useThru() returns the raw context value if you need direct access to the wallet instance, the current accounts, the selected account, or the Thru RPC client.
Example
Related exports
The root package also re-exportsBrowserSDK, ErrorCode, ConnectOptions, SDKEvent, and the shared chain types ConnectResult, IThruChain, SignMessageParams, SignMessageResult, and WalletAccount.