useDisconnect

Description

This hook provides functionality for disconnecting from a smart account. It handles the disconnection process and manages related states, such as whether the process is pending or if an error occurred. The hook can execute both synchronously and asynchronously.

Returns

The useDisconnect hook returns an object containing the following properties and functions:

  • disconnect (() => void): A synchronous function to disconnect from the smart account. It manages internal states such as pending and error states.

  • disconnectAsync (() => Promise<void>): An asynchronous function to disconnect from the smart account, returning a promise. This function allows the use of async/await syntax for handling the disconnection process.

  • isPending (boolean): A boolean indicating whether the disconnection process is currently pending.

  • error (Error | null): An error object if an error occurred during the disconnection process, otherwise null.

Example

import React from 'react';
import { useDisconnect } from "@cometh/connect-react-hooks";

const DisconnectButton = () => {
  const { disconnect, isPending, error } = useDisconnect();

  return (
    <div>
      <button onClick={disconnect} disabled={isPending}>
        {isPending ? 'Disconnecting...' : 'Disconnect'}
      </button>
      {error && <p style={{ color: 'red' }}>Error: {error.message}</p>}
    </div>
  );
};

export default DisconnectButton;

Last updated