# useSessionKeyClient

## Returns:

| Property  | Type                            | Description                                                                   |
| --------- | ------------------------------- | ----------------------------------------------------------------------------- |
| data      | SmartSessionClient or undefined | The session key client if it was successfully created, otherwise undefined.   |
| error     | Error or null                   | An error object if the client creation failed, otherwise null.                |
| isPending | boolean                         | A boolean indicating whether the client is currently being created.           |
| isSuccess | boolean                         | A boolean indicating whether the session key client was successfully created. |
| isError   | boolean                         | A boolean indicating whether an error occurred during the client creation.    |

## Usage Example:

```typescript
import { useSessionKeyClient } from "path/to/hook";

const Component = () => {
  const { data: sessionKeyClient, error, isPending, isSuccess, isError } =
    useSessionKeyClient({
      apiKey: "YOUR_API_KEY",
      sessionData: ..., 
      privateKey: ...,
    });

  if (isPending) return <p>Initializing session client...</p>;
  if (isError) return <p>Error: {error?.message}</p>;

  return (
    <div>
      {isSuccess && <p>Session Key Client Initialized!</p>}
      {/* Example usage */}
      <button
        onClick={() => {
          if (sessionKeyClient) {
            // Call methods on the session key client
            console.log("Session Key Client:", sessionKeyClient);
          }
        }}
      >
        Use Session Key Client
      </button>
    </div>
  );
};
```

## How It Works:

This hook leverages wagmi’s useQuery to initialize the SmartSessionClient asynchronously. The process involves:

1\. Using the useSessionKeySigner hook to retrieve the session key signer based on the provided session data and private key.

2\. Verifying that the smartAccountClient and sessionKeySigner are available.

3\. Calling createSessionSmartAccountClient to initialize the session key client.

4\. Returning the query result containing the client and its state.

## Error Handling:

If an error occurs during the client initialization, the error object will provide details about what went wrong. You can use this to display user-friendly error messages.

## Customization:

You can customize the behavior of the query by extending it through wagmi options (e.g., setting stale time, retries, or refetching conditions if needed).


---

# 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/session-keys/usesessionkeyclient.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.
