# useMinChat

the `useMinChat` hook is used to access the minchat object

```javascript
import { useMinChat } from '@minchat/reactnative'
```

```javascript
 const minchat = useMinChat()
```

### Get Connected User

get the user that is connected to the minchat instance. Returns a [User ](/reference/user.md)object.

```typescript
 const user = minchat?.getConnectedUser()
```

### Create User

You should create users in your MinChat application to initiate conversations with. Users are at the core of all conversations. MinChat applications are made up of users who chat in either group chats or one-to-one conversations.

in MinChat, a [User](/reference/user.md) is a person that uses your app. Typically, you will have one MinChat [User](/reference/user.md) for each user in your own database.&#x20;

Usually, you would create users based on the data from your database. A [User](/reference/user.md) is represented by a JSON object.

```typescript
const otherUser = await minchat?.createUser({ 
                                  username: "example-username", 
                                  name: "Example Name",
                                  avatar: "urltoavatar.com/avatar.jpg" //optional
                            })
                            
```

*You can view more details about the user parameters* [*here*](/reference/user.md)*.*

**note:** `createUser(...)` automatically creates a new user in the system, if a user with the same username already exists then it will reuse that user.

### Fetching a user

You can fetch an already existing user using either their username or their id.

<pre class="language-javascript"><code class="lang-javascript"><strong>
</strong><strong>const otherUser = await minchat?.fetchUser("example-username")
</strong>
</code></pre>

```javascript

const otherUser = await minchat?.fetchUserById("example-id")

```

### Updating a user

You can update an existing user's information

```javascript

const updatedUser = await minchat?.updateUserById("example-user-id",
                              { 
                                  name: "Updated Name",
                                  avatar: "urltoavatar.com/updated-avatar.jpg" 
                              })
                            
```

*You can view more details about the user parameters* [*here*](/reference/user.md)*.*


---

# 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.minchat.io/react-native-sdk/useminchat.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.
