useSetConnectionStatus

Hook for setting the connectionStatus of the wallet which is returned by the useConnectionStatus hook

This is only useful if you are manually connecting a wallet instance as mentioned in Build your Wallet

Example

import {
useCreateWalletInstance,
useSetConnectionStatus,
useSetConnectedWallet,
metamaskWallet,
} from "@thirdweb-dev/react";
const walletConfig = metamaskWallet();
function Example() {
const createWalletInstance = useCreateWalletInstance();
const setConnectionStatus = useSetConnectionStatus();
const setConnectedWallet = useSetConnectedWallet();
// Call this function to connect your wallet
const handleConnect = async () => {
// 1. create instance
const walletInstance = createWalletInstance(walletConfig);
setConnectionStatus("connecting");
try {
// 2. Call `connect` method of your wallet
await walletInstance.connect(
connectOptions, // if your wallet.connect method accepts any options, specify it here
);
// 3. Set connected wallet
setConnectedWallet(walletInstance);
props.close();
} catch (e) {
setConnectionStatus("disconnected");
console.error("failed to connect", e);
}
};
return <div> ... </div>;
}
function useSetConnectionStatus(): (status: ConnectionStatus) => void;

Returns

let returnType: (status: ConnectionStatus) => void;

A function that sets the connectionStatus of the wallet