React
The React adapter (@txnlab/use-wallet-react) provides a set of hooks and components for integrating use-wallet into React applications. This guide covers how to set up the adapter and use its features effectively.
Setup
After installing the package and any required wallet dependencies (see Installation) and configuring your WalletManager, wrap your application with the WalletProvider:
import {
WalletProvider,
WalletManager,
NetworkId,
} from '@txnlab/use-wallet-react'
// Create manager instance (see Configuration guide)
const manager = new WalletManager({
wallets: [...],
networks: {...},
defaultNetwork: NetworkId.TESTNET // or just 'testnet'
})
function App() {
return (
<WalletProvider manager={manager}>
<YourApp />
</WalletProvider>
)
}The provider makes the wallet functionality available throughout your application via React hooks.
Using the Hooks
The React adapter provides two hooks for accessing wallet functionality. In v4.0.0, network-related features were moved from useWallet into a new useNetwork hook to provide better separation of concerns:
useWallet
The useWallet hook provides access to wallet management features. Here's an example showing some commonly used values:
For a complete list of all available properties and methods, see the useWallet API Reference.
useNetwork
The useNetwork hook serves two primary functions: managing the active network and supporting runtime node configuration.
Active network management (previously part of useWallet) enables users to switch between different networks.
Runtime node configuration, introduced in v4.0.0, enables users to override the application's default node settings and connect to any Algorand node. See the Runtime Node Configuration guide for details about implementing this feature.
For a complete list of all available properties and methods, see the useNetwork API Reference.
Next Steps
Check out the Connect Wallet Menu guide for creating a simple wallet connection interface
Learn about transaction signing patterns in the Signing Transactions guide
Explore network features in the Switching Networks and Runtime Node Configuration guides
Read the API Reference for detailed documentation of the library's main exports
Browse Example Projects for working implementations in Vite (React) and Next.js
Last updated