useWalletUiCluster
The useWalletUiCluster hook provides access to the currently selected Solana cluster, the list of all available clusters, and a function to switch the active cluster.
The available clusters are configured in the main WalletUi provider.
Return Value
Section titled “Return Value”The hook returns an object with the following properties:
| Name | Type | Description |
|---|---|---|
cluster | SolanaCluster | The currently selected Solana cluster object. |
clusters | SolanaCluster[] | An array of all available cluster objects. |
setCluster | (clusterId: SolanaClusterId) => void | A function to set the active cluster by its ID. |
Example
Section titled “Example”This example shows how to build a simple cluster selector.
import { useWalletUiCluster } from '@wallet-ui/react';
function ClusterSelector() { const { cluster, clusters, setCluster } = useWalletUiCluster();
return ( <div> <p>Current Cluster: {cluster.label}</p> <div> {clusters.map(c => ( <button key={c.id} onClick={() => setCluster(c.id)} disabled={c.id === cluster.id}> Switch to {c.label} </button> ))} </div> </div> );}