BluxBlux

useSwitchNetwork

Change the active network in your React app using the Blux SDK.

The useSwitchNetwork hook returns a switchNetwork function for changing the currently active network.

Switching the active network affects components like the profile modal and hooks such as useBalance, useAccount, and useTransactions when no explicit network parameter is provided to them.

Import

import { networks, useSwitchNetwork } from "@bluxcc/react";

Usage

import { networks, useSwitchNetwork } from "@bluxcc/react";

const Comp = () => {
  const { switchNetwork } = useSwitchNetwork();

  const changeNetwork = () => {
    switchNetwork(networks.mainnet);
  };

  return (
    <div>
      <button onClick={changeNetwork}>Change network to mainnet</button>
    </div>
  );
};

Return Type

switchNetwork

(network: string) => void

Call with a network value from the networks object to update the active network across your app.

On this page