Skip to main content

useDisconnect

Hook for disconnecting from an Ethereum node.

import { useDisconnect } from "@thirdweb-dev/react";

Usage

import { useDisconnect, Web3Button } from "@thirdweb-dev/react";

function App() {
const disconnect = useDisconnect();

return (
<Web3Button
action={() =>
disconnect()
}
>
Disconnect
</Web3Button>
);
}

Configuration

reconnectPrevious

By default, the hook will not attempt to reconnect to the previously connected node.

If you want the hook to attempt to reconnect to the last node, set this option to true.

import { useDisconnect, Web3Button } from "@thirdweb-dev/react";

function App() {
const disconnect = useDisconnect({
reconnectPrevious: true,
});

return (
<Web3Button
action={() =>
disconnect()
}
>
Disconnect
</Web3Button>
);
}