# 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

```tsx
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;

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cometh.io/integrations/react-hooks/usedisconnect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
