Skip to content

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.

The hook returns an object with the following properties:

NameTypeDescription
clusterSolanaClusterThe currently selected Solana cluster object.
clustersSolanaCluster[]An array of all available cluster objects.
setCluster(clusterId: SolanaClusterId) => voidA function to set the active cluster by its ID.

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>
);
}