> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Leave A Group

> Leave groups, listen for real-time leave events, and handle missed leave events using the CometChat React Native SDK.

<Info>
  **Quick Reference** - Leave a group:

  ```javascript theme={null}
  await CometChat.leaveGroup("GUID");
  ```
</Info>

<Note>
  **Available via:** [SDK](/sdk/react-native/leave-group) | [REST API](/rest-api/group-members/kick)
</Note>

## Leave a Group

In order to stop receiving updates and messages for any particular joined group, you will have to leave the group using the `leaveGroup()` method.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var GUID = "GUID"; // guid of the group to join

    CometChat.leaveGroup(GUID).then(
    hasLeft => {
      console.log("Group left successfully:", hasLeft);
    }, error => {
      console.log("Group leaving failed with exception:", error);
    }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    var GUID: string = "GUID";

    CometChat.leaveGroup(GUID).then(
      (hasLeft: boolean) => {
          console.log("Group left successfully:", hasLeft);
      }, (error: CometChat.CometChatException) => {
          console.log("Group leaving failed with exception:", error);
      }
    );
    ```
  </Tab>
</Tabs>

| Parameter | Description                                  |
| --------- | -------------------------------------------- |
| `GUID`    | The UID of the group you would like to leave |

Once a group is left, the user will no longer receive any updates or messages pertaining to the group.

<Accordion title="Response">
  **On Success** — `leaveGroup()` returns a boolean:

  | Parameter | Type    | Description                                            | Sample Value |
  | --------- | ------- | ------------------------------------------------------ | ------------ |
  | `hasLeft` | boolean | Indicates whether the user successfully left the group | `true`       |
</Accordion>

## Real-time Group Member Left Events

*In other words, as a member of a group, how do I know if someone has left it?*

If a user leaves any group, The members of the group receive a real-time event in the `onGroupMemberLeft()` method of the `GroupListener` class.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    CometChat.addGroupListener(
      "UNIQUE_LISTENER_ID",
      new CometChat.GroupListener({
          onGroupMemberLeft: (message, leavingUser, group) => {
              console.log("User left", { message, leavingUser, group });
          }
      })
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    CometChat.addGroupListener(
      "UNIQUE_LISTENER_ID",
      new CometChat.GroupListener({
          onGroupMemberLeft: (message: CometChat.Action, leavingUser: CometChat.User, group: CometChat.Group) => {
              console.log("User left", { message, leavingUser, group });
          }
      })
    );
    ```
  </Tab>
</Tabs>

<Warning>
  Always remove group listeners when the component unmounts using `CometChat.removeGroupListener(listenerId)`. Failing to remove listeners can cause memory leaks and duplicate event handling.
</Warning>

## Missed Group Member Left Events

*In other words, as a member of a group, how do I know if someone has left it when my app is not running?*

When you retrieve the list of previous messages if a member has left any group that the logged-in user is a member of, the list of messages will contain an `Action` message. An `Action` message is a sub-class of `BaseMessage` class.

For the group member left event, in the `Action` object received, the following fields can help you get the relevant information-

1. `action` - `left`
2. `actionBy` - User object containing the details of the user who left the group
3. `actionFor` - Group object containing the details of the group the user has left

## Best Practices

<AccordionGroup>
  <Accordion title="Clean up local state after leaving">
    After successfully leaving a group, remove any local references to the group's messages, members, or conversation data. This prevents stale data from appearing in your UI.
  </Accordion>

  <Accordion title="Group owners should transfer ownership before leaving">
    If the logged-in user is the group owner, consider transferring ownership to another admin or member before leaving. Leaving as the owner may have different behavior depending on your app's configuration.
  </Accordion>
</AccordionGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="leaveGroup fails with error">
    Verify the GUID is correct and the logged-in user is actually a member of the group. You can check membership using `getGroup()` and the `hasJoined` property.
  </Accordion>

  <Accordion title="Still receiving messages after leaving">
    Ensure the `leaveGroup()` call completed successfully (resolved the promise). Also remove any active group listeners for that group to stop receiving real-time events.
  </Accordion>
</AccordionGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Join a Group" icon="right-to-bracket" href="/sdk/react-native/join-group">
    Join public or password-protected groups
  </Card>

  <Card title="Delete a Group" icon="trash" href="/sdk/react-native/delete-group">
    Delete groups and handle related cleanup
  </Card>

  <Card title="Group Members" icon="users" href="/sdk/react-native/group-members">
    Manage members, roles, and permissions within groups
  </Card>

  <Card title="Retrieve Groups" icon="layer-group" href="/sdk/react-native/retrieve-groups">
    Fetch group lists and group details
  </Card>
</CardGroup>
