> For the complete documentation index, see [llms.txt](https://docs.cometh.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cometh.io/integrations/react-hooks/useconnect.md).

# useConnect

## Description

This hook allows you to initiate a connection to a smart account with optional parameters and can handle the process both synchronously and asynchronously.

## Parameters

The `useConnect` hook itself does not take parameters. However, the primary functions returned by the hook, `connect` and `connectAsync`, accept the following optional parameters:

```typescript
type ConnectParameters = {
    address?: Address;
    passKeyName?: string;
};
```

## Returns

* **connect** (`(params?: ConnectParameters) => void`): Initiates the connection process. It accepts an optional `params` object to specify connection details. It handles state changes for pending status and errors internally.
* **connectAsync** (`(params?: ConnectParameters) => Promise<void>`): An asynchronous function similar to `connect`, but returns a promise, allowing for usage with `async/await` syntax.
* **isPending** (`boolean`): A boolean value indicating whether the connection process is currently pending (`true`) or not (`false`).
* **error** (`Error | null`): An error object if an error occurred during the connection process, otherwise `null`.

## Example

```tsx
import React, { useState } from 'react';
import { useConnect } from "@cometh/connect-react-hooks";

const ConnectAccount = () => {
  const { connect, isPending, error } = useConnect();
  const [address, setAddress] = useState('');

  const handleConnect = () => {
    connect({ address });
  };

  return (
    <div>
      <h1>Connect to Smart Account</h1>
      <input
        type="text"
        value={address}
        onChange={(e) => setAddress(e.target.value)}
        placeholder="Enter smart account address"
      />
      <button onClick={handleConnect} disabled={isPending}>
        {isPending ? 'Connecting...' : 'Connect'}
      </button>
      {error && <p style={{ color: 'red' }}>Error: {error.message}</p>}
    </div>
  );
};

export default ConnectAccount;

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
