Skip to main content
Version: v4

Group Members

Overview

CometChatGroupMembers is a Component that displays all users added or invited to a group, granting them access to group discussions, shared content, and collaborative features. Group members can communicate in real-time via messaging, voice and video calls, and other activities. They can interact, share files, and join calls based on group permissions set by the administrator or owner.

Image

Usage

Integration

The following code snippet illustrates how you can directly incorporate the Group Members component into your Application.


import { CometChat } from '@cometchat/chat-sdk-javascript';
import { CometChatGroupMembers } from '@cometchat/chat-uikit-react'
import React from 'react'

const GroupMembersDemo = () => {

const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
})
}, []);
return (
<>
{
chatGroup &&
<CometChatGroupMembers
group={chatGroup}
/>
}
</>
)
}

export default GroupMembersDemo;


Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

1. onSelect

The onSelect action is activated when you select the done icon while in selection mode. This returns a list of all the group members that you have selected.

This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatGroupMembers,
SelectionMode,
} from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
function handleOnSelect(
groupMembers: CometChat.GroupMember,
selected: boolean
): void {
console.log(groupMembers);
//your custom onSelect actions
}
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
selectionMode={SelectionMode.multiple}
onSelect={handleOnSelect}
/>
)}
</>
);
};

export default GroupMembersDemo;
2. onItemClick

The onItemClick event is activated when you click on the Group Members List item. This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
function handleOnItemClick(groupMembers: CometChat.GroupMember): void {
console.log(groupMembers, "your custom on item click action");
}
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
onItemClick={handleOnItemClick}
/>
)}
</>
);
};

export default GroupMembersDemo;
3. onBack

OnBack is triggered when you click on the back button of the Group Members component. You can override this action using the following code snippet.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
function handleOnBack() {
console.log("your custom on back action");
}
return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} onBack={handleOnBack} />
)}
</>
);
};

export default GroupMembersDemo;
4. onClose

onClose is triggered when you click on the close button of the Group Members component. You can override this action using the following code snippet.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
function handleOnClose(): void {
console.log("Your custom on close actions");
}
return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} onClose={handleOnClose} />
)}
</>
);
};

export default GroupMembersDemo;
5. onEmpty

This action allows you to specify a callback function to be executed when a certain condition, typically the absence of data or content, is met within the component or element.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
function handleOnEmpty(): void {
console.log("your custom on empty actions");
}
return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} onEmpty={handleOnEmpty} />
)}
</>
);
};

export default GroupMembersDemo;
6. onError

This action doesn't change the behavior of the component but rather listens for any errors that occur in the Group Members component.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
function handleOnError(error: CometChat.CometChatException): void {
//Your Custom on error actions
}
return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} onEmpty={handleOnEmpty} />
)}
</>
);
};

export default GroupMembersDemo;

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.

1. GroupMembersRequestBuilder

The GroupMembersRequestBuilder enables you to filter and customize the group members list based on available parameters in GroupMembersRequestBuilder. This feature allows you to create more specific and targeted queries when fetching groups. The following are the parameters available in GroupMembersRequestBuilder

MethodsTypeDescription
setLimitnumbersets the number of group members that can be fetched in a single request, suitable for pagination
setSearchKeywordStringused for fetching group members matching the passed string
setScopesArray<String>used for fetching group members based on multiple scopes

Example

In the example below, we are applying a filter to the Group Members by setting the limit to two and setting the scope to show only admin and moderator.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
groupMemberRequestBuilder={new CometChat.GroupMembersRequestBuilder(
"guid"
)
.setLimit(2)
.setScopes(["admin", "moderator"])}
/>
)}
</>
);
};

export default GroupMembersDemo;
2. SearchRequestBuilder

The SearchRequestBuilder uses GroupMembersRequestBuilder enables you to filter and customize the search list based on available parameters in GroupMembersRequestBuilder. This feature allows you to keep uniformity between the displayed Group Members List and searched Group Members List.

Example

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("guid").then((group) => {
setChatGroup(group);
});
}, []);
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
searchRequestBuilder={new CometChat.GroupMembersRequestBuilder("guid")
.setLimit(2)
.setSearchKeyword("**")}
/>
)}
</>
);
};

export default GroupMembersDemo;

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.

Events emitted by the Group Members component is as follows.

EventDescription
ccGroupMemberBannedTriggers when the group member banned from the group successfully
ccGroupMemberKickedTriggers when the group member kicked from the group successfully
ccGroupMemberScopeChangedTriggers when the group member scope is changed in the group
const ccGroupMemberBanned = CometChatGroupEvents.ccGroupMemberBanned.subscribe(
(item: IGroupMemberKickedBanned) => {
//Your Code
}
);

const ccGroupMemberKicked = CometChatGroupEvents.ccGroupMemberKicked.subscribe(
(item: IGroupMemberKickedBanned) => {
//Your Code
}
);

const ccGroupMemberScopeChanged =
CometChatGroupEvents.ccGroupMemberScopeChanged.subscribe(
(item: IGroupMemberScopeChanged) => {
//Your Code
}
);

ccGroupMemberBanned?.unsubscribe();

ccGroupMemberKicked?.unsubscribe();

ccGroupMemberScopeChanged?.unsubscribe();

Customization

To fit your app's design requirements, you can customize the appearance of the Group Members component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

1. GroupMembers Style

You can set the GroupMembersStyle to the Group Members Component to customize the styling.

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatGroupMembers,
GroupMembersStyle,
} from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
const groupMembersStyle = new GroupMembersStyle({
background: "#b17efc",
searchPlaceholderTextColor: "#ffffff",
titleTextColor: "#000000",
searchBackground: "#5718b5",
});
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
groupMembersStyle={groupMembersStyle}
/>
)}
</>
);
};

export default GroupMembersDemo;

List of properties exposed by GroupMembersStyle:

PropertyDescriptionCode
borderUsed to set borderborder?: string,
borderRadiusUsed to set border radiusborderRadius?: string;
backgroundUsed to set background colourbackground?: string;
heightUsed to set heightheight?: string;
widthUsed to set widthwidth?: string;
titleTextFontUsed to set title text fonttitleTextFont?: string,
titleTextColorUsed to set title text colortitleTextColor?: string;
searchPlaceholderTextFontUsed to set search placeholder fontsearchPlaceholderTextFont?: string;
searchPlaceholderTextColorUsed to set search placeholder colorsearchPlaceholderTextColor?: string;
searchTextFontUsed to set search text fontsearchTextFont?: string;
searchTextColorUsed to set search text colorsearchTextColor?: string;
emptyStateTextFontUsed to set empty state text fontemptyStateTextFont?: string;
emptyStateTextColorUsed to set empty state text coloremptyStateTextColor?: string;
errorStateTextFontUsed to set error state text fonterrorStateTextFont?: string;
errorStateTextColorUsed to set error state text colorerrorStateTextColor?: string;
loadingIconTintUsed to set loading icon tintloadingIconTint?: string;
searchIconTintUsed to set search icon tintsearchIconTint?: string;
searchBorderUsed to set search bordersearchBorder?: string;
searchBorderRadiusUsed to set search border radiussearchBorderRadius?: string;
searchBackgroundUsed to set search background colorsearchBackground?: string;
onlineStatusColorUsed to set online status coloronlineStatusColor?: string;
separatorColorUsed to set separator colorseparatorColor?: string;
boxShadowUsed to set box shadowboxShadow?: string;
backButtonIconTintUsed to set back button icon tintbackButtonIconTint?: string;
closeButtonIconTintUsed to set close button icon tintcloseButtonIconTint?: string;
privateGroupIconBackgroundUsed to set private group icon bgprivateGroupIconBackground?: string;
passwordGroupIconBackgroundUsed to set password group icon bgpasswordGroupIconBackground?: string;
paddingUsed to set paddingpadding?: string;
2. GroupScope Style

You can set the GroupScope to the Group Members Component to customize the styling.

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatGroupMembers,
ChangeScopeStyle,
} from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
const groupScopeStyle = new ChangeScopeStyle({
activeTextBackground: "#b17efc",
activeTextColor: "#000000",
arrowIconTint: "b17efc",
buttonTextColor: "#ffffff",
});
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
groupScopeStyle={groupScopeStyle}
/>
)}
</>
);
};

export default GroupMembersDemo;

List of properties exposed by ChangeScopeStyle:

PropertyDescriptionCode
borderUsed to set borderborder?: string,
borderRadiusUsed to set border radiusborderRadius?: string;
backgroundUsed to set background colourbackground?: string;
heightUsed to set heightheight?: string;
widthUsed to set widthwidth?: string;
titleTextFontUsed to set title text fonttitleTextFont?: string,
titleTextColorUsed to set title text colortitleTextColor?: string;
activeTextFontUsed to set active text fontactiveTextFont?: string;
activeTextColorUsed to set active text coloractiveTextColor?: string;
activeTextBackgroundUsed to set active text backgroundactiveTextBackground?: string;
arrowIconTintUsed to set arrow icon tintarrowIconTint?: string;
textFontUsed to set text fonttextFont?: string;
textColorUsed to set text colortextColor?: string;
optionBackgroundUsed to set option background coloroptionBackground?: string;
optionBorderUsed to set option borderoptionBorder?: string;
optionBorderRadiusUsed to set option border radiusoptionBorderRadius?: string;
hoverTextFontUsed to set hover text fonthoverTextFont?: string;
hoverTextColorUsed to set hover text colorhoverTextColor?: string;
hoverTextBackgroundUsed to set hover text backgroundhoverTextBackground?: string;
buttonTextFontUsed to set button text fontbuttonTextFont?: string;
buttonTextColorUsed to set button text colorbuttonTextColor?: string;
buttonBackgroundUsed to set button background colorbuttonBackground?: string;
closeIconTintUsed to set close icon tintcloseIconTint?: string;
3. Avatar Style

To apply customized styles to the Avatar component in the Group Members Component, you can use the following code snippet. For further insights on Avatar Styles refer

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatGroupMembers,
AvatarStyle,
} from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
const avatarStyle = new AvatarStyle({
backgroundColor: "#cdc2ff",
border: "2px solid #6745ff",
borderRadius: "10px",
outerViewBorderColor: "#ca45ff",
outerViewBorderRadius: "5px",
nameTextColor: "#4554ff",
});
return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} avatarStyle={avatarStyle} />
)}
</>
);
};

export default GroupMembersDemo;
4. ListItem Style

To apply customized styles to the ListItemStyle component in the Group Members Component, you can use the following code snippet. For further insights on ListItemStyle Styles refer

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatGroupMembers,
ListItemStyle,
} from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
const listItemStyle = new ListItemStyle({
width: "100%",
height: "100%",
border: "2px solid red",
});
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
listItemStyle={listItemStyle}
/>
)}
</>
);
};

export default GroupMembersDemo;
5. StatusIndicator Style

To apply customized styles to the Status Indicator component in the Group Members Component, You can use the following code snippet. For further insights on Status Indicator Styles refer

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
const statusIndicatorStyle = {
background: "#db35de",
height: "10px",
width: "10px",
};
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
statusIndicatorStyle={statusIndicatorStyle}
/>
)}
</>
);
};

export default GroupMembersDemo;

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);
return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
titleAlignment={TitleAlignment.left}
title="Your Custom Title"
userPresencePlacement={UserPresencePlacement.right}
/>
)}
</>
);
};

export default GroupMembersDemo;

Default:

Image

Custom:

Image

Below is a list of customizations along with corresponding code snippets

PropertyDescriptionCode
title report Used to set title in the app headingtitle="Your Custom Title"
errorStateText report Used to set a custom text response when some error occurs on fetching the list of group memberserrorStateText="your custom error state text"
emptyStateText report Used to set a custom text response when fetching the group members has returned an empty listemptyStateText="your custom empty state text"
searchIconURLUsed to set search Icon in the search fieldsearchIconURL="Your Custom search icon"
loadingIconURLUsed to set loading IconloadingIconURL="your custom loading icon url"
closeButtonIconURLUsed to set close button IconcloseButtonIconURL="your custom close icon url"
dropDownIconURLUsed to set the dropdown IcondropDownIconURL='Your Custom Dropdown Icon'
backButtonIconURLUsed to set the back button IconbackButtonIconURL='Your Custom back Icon'
hideErrorUsed to hide error on fetching groupshideError={true}
hideSearchUsed to toggle visibility for search boxhideSearch={true}"
hideSeparatorUsed to hide the divider separating the user itemshideSeparator={true}
disableLoadingState report disable the loading statedisableLoadingState={true}
disableUsersPresenceUsed to toggle functionality to show user's presencedisableUsersPresence={true}
showBackButtonHides / shows the back button as per the boolean valueshowBackButton={true}
selectionModeset the number of group members that can be selected, SelectionMode can be single, multiple or none.selectionMode={SelectionMode.multiple}
titleAlignmentAlignment of the heading text for the componenttitleAlignment={TitleAlignment.center}
userPresencePlacement report determines the position where the user presence indicator is displayed relative to the user's avatar or name, with right or bottom indicating it's displayed to the right or bottom of the user's list.userPresencePlacement={UserPresencePlacement.right}
group report Used to pass group object of which group members will be showngroup={chatGroup}
searchKeyword report Used to set the search keywordsearchKeyword='alice'
searchPlaceholder report Used to set custom search placeholder textsearchPlaceholder='Custom Search PlaceHolder'

Advance

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.


ListItemView

With this property, you can assign a custom ListItem to the Group Members Component.

listItemView = { getListItemView };

Example

Default:

Image

Custom:

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

const getListItemView = (groupMembers: CometChat.GroupMember) => {
return (
<div
style={{
display: "flex",
alignItems: "left",
padding: "10px",
border: "2px solid #e9baff",
borderRadius: "20px",
background: "#6e2bd9",
}}
>
<cometchat-avatar
image={groupMembers.getAvatar()}
name={groupMembers.getName()}
/>

<div style={{ display: "flex", paddingLeft: "10px" }}>
<div
style={{ fontWeight: "bold", color: "#ffffff", fontSize: "14px" }}
>
{groupMembers.getName()}
<div
style={{ color: "#ffffff", fontSize: "10px", textAlign: "left" }}
>
{groupMembers.getStatus()}{" "}
</div>
</div>
</div>
</div>
);
};

return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
listItemView={getListItemView}
/>
)}
</>
);
};

export default GroupMembersDemo;

SubtitleView

You can customize the subtitle view for each group members to meet your requirements

subtitleView = { getSubtitleView };

Default:

Image

Custom:

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

const getSubtitleView = (
groupMembers: CometChat.GroupMember
): JSX.Element => {
function formatTime(timestamp: number) {
const date = new Date(timestamp * 1000);
return date.toLocaleString();
}
if (groupMembers instanceof CometChat.GroupMember) {
return (
<div
style={{
display: "flex",
alignItems: "left",
padding: "2px",
fontSize: "10px",
}}
>
<div style={{ color: "gray" }}>
Last Active At: {formatTime(groupMembers.getLastActiveAt())}
</div>
</div>
);
} else {
return <></>;
}
};

return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
subtitleView={getSubtitleView}
/>
)}
</>
);
};

export default GroupMembersDemo;

TailView

You can customize the tail view for each group members to meet your requirements

tailView = { getTailView };

Default:

Image

Custom:

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

function getTailView(groupMember: CometChat.GroupMember): JSX.Element {
return (
<div
style={{
color: "#5a00a8",
border: "1px solid #5a00a8",
borderRadius: "12px",
padding: "5px",
}}
>
{groupMember.getScope()}
</div>
);
}

return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} tailView={getTailView} />
)}
</>
);
};

export default GroupMembersDemo;

EmptyStateView

You can set a custom EmptyStateView using emptyStateView to match the empty view of your app.

emptyStateView={getEmptyStateView()}

Default:

Image

Custom:

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

const getEmptyStateView = () => {
return (
<div style={{ color: "#d6cfff", fontSize: "30px", font: "bold" }}>
Your Custom Empty State
</div>
);
};

return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
emptyStateView={getEmptyStateView()}
/>
)}
</>
);
};

export default GroupMembersDemo;

ErrorStateView

You can set a custom ErrorStateView using errorStateView to match the error view of your app.

errorSateView={getErrorStateView()}

Default:

Image

Custom:

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

const getErrorStateView = () => {
return (
<div style={{ height: "100vh", width: "100vw" }}>
<img
src="image"
alt="error icon"
style={{
height: "100px",
width: "100px",
marginTop: "250px",
justifyContent: "center",
}}
></img>
</div>
);
};

return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
errorSateView={getErrorStateView()}
/>
)}
</>
);
};

export default GroupMembersDemo;

You can set the Custom Menu view to add more options to the Group Members component.

menus={getMenus()}
Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatGroupMembers } from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

const getMenus = () => {
const handleReload = () => {
window.location.reload();
};
const getButtonStyle = () => {
return {
height: "20px",
width: "20px",
border: "none",
borderRadius: "0",
background: "transparent",
buttonIconTint: "#7E57C2",
};
};
return (
<div style={{ marginRight: "20px" }}>
<cometchat-button
iconURL="Icon"
buttonStyle={JSON.stringify(getButtonStyle())}
onClick={handleReload}
>
{" "}
</cometchat-button>
</div>
);
};

return (
<>
{chatGroup && (
<CometChatGroupMembers group={chatGroup} menus={getMenus()} />
)}
</>
);
};

export default GroupMembersDemo;

Options

You can set the Custom options to the Group Members component.

Image
GroupMembersDemo.tsx
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
CometChatGroupMembers,
CometChatOption,
} from "@cometchat/chat-uikit-react";
import React from "react";

const GroupMembersDemo = () => {
const [chatGroup, setChatGroup] = React.useState<CometChat.Group>();

React.useEffect(() => {
CometChat.getGroup("uid").then((group) => {
setChatGroup(group);
});
}, []);

return (
<>
{chatGroup && (
<CometChatGroupMembers
group={chatGroup}
options={(
group: CometChat.Group,
groupMember: CometChat.GroupMember
) => {
const customOptions = [
new CometChatOption({
id: "1",
title: "Title",
iconURL: "Icon",
backgroundColor: "transparent",
onClick: () => {
console.log(
"Custom option clicked for group members:",
groupMember
);
},
iconTint: "#6851D6",
titleColor: "#000000",
}),
];
return customOptions;
}}
/>
)}
</>
);
};

export default GroupMembersDemo;