tencent cloud

即时通信 IM

动态与公告
产品动态
公告
产品简介
产品概述
基本概念
应用场景
功能介绍
账号系统
用户资料与关系链
消息管理
群组相关
公众号系统
音视频通话 Call
使用限制
购买指南
计费概述
价格说明
购买指引
续费指引
停服说明
退费说明
开发指引
Demo 专区
开通服务
体验 Demo
快速跑通
下载中心
SDK & Demo 源码
更新日志
聊天互动(含 UI)
TUIKit 组件介绍
快速开始
全功能接入
单功能接入
AI 集成
构建基础界面
更多特性
定义外观
国际化界面语言
推送服务(Push)
服务概述
名词解释
开通服务
快速跑通
厂商通道
数据统计
排查工具
客户端 API
服务端 API
推送回调
高级功能
更新日志
错误码
常见问题
智能客服
功能概述
快速入门
集成指引
管理员操作手册
客服操作手册
更多实践
直播间搭建
AI 聊天机器人方案
超大娱乐协作社群
Discord 实现指南
游戏内集成 Chat 指南
类 WhatsApp Channel 搭建方案
发送红包
Chat 应对防火墙限制相关
无 UI 集成
快速开始
集成 SDK
初始化
登录登出
消息相关
会话相关
群组相关
社群话题
用户管理
离线推送
云端搜索
本地搜索
公众号
客户端 API
JavaScript
Android
iOS & macOS
Swift
Flutter
Electron
Unity
React Native
C 接口
C++
服务端 API
生成 UserSig
REST API
第三方回调
控制台指南
新版控制台介绍
创建并升级应用
基本配置
功能配置
账号管理
群组管理
公众号管理
回调配置
用量统计
资源包查看指南
实时监控
开发辅助工具
访问管理
高级功能
常见问题
uni-app 常见问题
购买相关问题
SDK 相关问题
账号鉴权相关问题
用户资料与关系链相关问题
消息相关问题
群组相关问题
直播群相关问题
昵称头像相关问题
协议与认证
服务等级协议
安全合规认证
IM 政策
隐私政策
数据隐私和安全协议
平滑迁移方案
平滑迁移完整版
平滑迁移简化版
错误码
联系我们

ConversationList

PDF
聚焦模式
字号
最后更新时间: 2025-07-22 16:06:20
ConversationList 组件主要负责会话列表功能,它包含了 Header 部分和 List 部分,具有搜索会话、创建会话、会话置顶、会话删除等功能。
本文档将详细介绍该组件的基础使用,组件定制,自由组合以及组件的 props 参数列表。
会话列表
会话操作
会话搜索
创建会话













基础使用

ConversationList 组件没有任何必须属性,您可以通过以下代码使用 ConversationList
import { UIKitProvider, ConversationList } from '@tencentcloud/chat-uikit-react';

const App = () => {
return (
<UIKitProvider>
<ConversationList />
</UIKitProvider>
);
};

自定义组件

ConversationList 为用户自定义提供了丰富且多维度的 Props 接口,允许用户自定义功能、UI、模块等。
ConversationList 组件提供了多个可替换的子组件,允许用户自定义 Header, List, ConversationPreview, ConversationCreate, ConversationSearch, ConversationActions, Avatar, Placeholder 等。同时,用户还可以利用默认子组件进行二次开发定制。

基础功能开关

通过设置 enableSearch, enableCreateenableActions 参数,您可以灵活地控制 ConversationList 中的搜索会话、创建会话和会话操作功能的显示。
<ConversationList enableSearch={false} />
<ConversationList enableCreate={false} />
<ConversationList enableActions={false} />
enableSearch={false}
enableCreate={false}
enableActions={false}










数据筛选和排序

ConversationList 组件提供了 filterConversationsortConversation 属性,可以让您对会话列表数据进行筛选和排序。

筛选会话

要筛选会话列表数据,您可以给 filterConversation 属性传递一个筛选函数。这个函数接收一个 ConversationModel 数组作为参数,然后应该返回一个新数组,只包含符合您筛选条件的会话。
下面是一个使用 filterConversation 属性来只显示“包含未读消息”的会话的例子:
import { ConversationList } from '@tencentcloud/chat-uikit-react';
import type { ConversationModel } from '@tencentcloud/chat-uikit-react';

<ConversationList
filter={(conversationList: ConversationModel[]) =>
conversationList.filter(conversation => conversation.unreadCount > 0)}
/>

排序会话

要排序会话列表数据,您可以给 sortConversation 属性传递一个排序函数。这个函数接收一个 ConversationModel 数组作为参数,然后应该返回一个新数组,按照您的排序标准对会话进行排序。
下面是一个使用 sortConversation 属性来按照“最新消息时间倒序”排序会话列表的例子:
import { ConversationList } from '@tencentcloud/chat-uikit-react';
import type { ConversationModel } from '@tencentcloud/chat-uikit-react';

<ConversationList
sort={(conversationList: ConversationModel[]) =>
conversationList.sort(
(a, b) => (+(b?.lastMessage?.lastTime || 0)) - (+(a?.lastMessage?.lastTime || 0)),
)}
/>
通过使用 filtersort 属性,您可以根据您的需求有效地筛选和排序会话列表数据。

自定义 actionsConfig

利用 actionsConfig 对 ConversationActions 的基础功能进行控制。
更多定制请详情参见 ConversationActions 章节。
import { ConversationList } from '@tencentcloud/chat-uikit-react';
import type { ConversationModel } from '@tencentcloud/chat-uikit-react';

<ConversationList
actionsConfig={{
enablePin: false,
onConversationDelete: (conversation: ConversationModel) => { console.log('Delete conversation success'); },
customConversationActions: {
'custom-actions-1': {
label: 'custom-actions',
onClick: (conversation: ConversationModel) => { console.log(conversation); },
},
},
}}
/>
enablePin: false
enableDelete: false
enableMute: false
customConversationActions













自定义 Placeholder

您可以通过传入 PlaceholderEmptyListPlaceholderLoading 以及 PlaceholderLoadError 来定制不同状态下的列表展示。
以下是定制一个新的 PlaceholderLoading 示例:
<ConversationList
PlaceholderEmptyList={<div>Empty List!!!</div>}
/>

自定义 Header

ConversationListHeader 负责 ConversationList Header 部分的渲染工作,作为包裹层渲染默认 ConversationSearchConversationCreate 。您可以通过传入 left、right 等属性进行自定义,同时,您也可以自定义整个组件。

Props

参数名
类型
默认值
说明
children
ReactNode
-
自定义会话列表头部中心组件。
<ConversationList> 中使用时,会默认传入 <ConversationSearch><ConversationCreate>
left
ReactElement
-
自定义会话列表头部左侧组件。
right
ReactElement
-
自定义会话列表头部右侧组件。
className
String
-
指定根元素类的 CSS 自定义名称。
style
React.CSSProperties
-
指定根元素样式的自定义样式。

基础定制

以下是在 Header 组件右侧添加一个新的功能按钮示例。
import {
ConversationList,
ConversationListHeader,
} from '@tencentcloud/chat-uikit-react';
import type { ConversationListHeaderProps } from '@tencentcloud/chat-uikit-react';

const CustomConversationListHeader = (props: ConversationListHeaderProps) => {
const CustomIcon = <div>自定义 Icon </div>;
return (
<ConversationListHeader {...props} right={CustomIcon} />
);
};
<ConversationList Header={CustomConversationListHeader} />

高阶定制

以下是实现一个简易的会话分组功能,按照全部会话、未读会话、单聊会话、群会话四个维度进行区分,通过点击不同分组按钮执行不同的筛选规则。
修改前
修改后












React
CSS
import { useState } from 'react';
import TUIChatEngine from '@tencentcloud/chat-uikit-engine';
import { ConversationList, UIKitProvider } from '@tencentcloud/chat-uikit-react';
import type { ConversationListHeaderProps, ConversationModel } from '@tencentcloud/chat-uikit-react';

const App = () => {
const [currentFilter, setCurrentFilter] = useState<string>('all');
const conversationGroupFilter: Record<string, (conversationList: ConversationModel[]) => ConversationModel[]> = {
all: (conversationList: ConversationModel[]) => conversationList,
unread: (conversationList: ConversationModel[]) => conversationList?.filter((item: ConversationModel) => item.unreadCount > 0),
c2c: (conversationList: ConversationModel[]) => conversationList?.filter((item: ConversationModel) => item.type === TUIChatEngine.TYPES.CONV_C2C),
group: (conversationList: ConversationModel[]) => conversationList?.filter((item: ConversationModel) => item.type === TUIChatEngine.TYPES.CONV_GROUP),
};

const CustomConversationListHeader = (props: IConversationListHeaderProps) => {
return (
<div className="conversation-group-wrapper">
<button className={currentFilter === 'all' ? 'btn-active' : 'btn-default'} onClick={() => setCurrentFilter('all')}>All</button>
<button className={currentFilter === 'unread' ? 'btn-active' : 'btn-default'} onClick={() => setCurrentFilter('unread')}>Unread</button>
<button className={currentFilter === 'c2c' ? 'btn-active' : 'btn-default'} onClick={() => setCurrentFilter('c2c')}>C2C</button>
<button className={currentFilter === 'group' ? 'btn-active' : 'btn-default'} onClick={() => setCurrentFilter('group')}>Group</button>
</div>
);
};

return (
<UIKitProvider>
<ConversationList
style={{ maxWidth: '300px', height: '600px' }}
Header={CustomConversationListHeader}
filter={conversationGroupFilter[currentFilter]}
/>
</UIKitProvider>
);
};
.conversation-group-wrapper {
display: flex;
justify-content: space-around;
align-items: center;
margin: 10px;
font-size: 14px;
.btn-default{
display: flex;
padding: 5px 10px;
border: 1px solid #b3b3b4;
color: #3b3d43;
background-color: transparent;
border-radius: 2px;
}
.btn-active{
display: flex;
padding: 5px 10px;
border: 1px solid #1c66e5;
color: #1c66e5;
background-color: transparent;
border-radius: 2px;
}
}

自定义 List

ConversationListContent 负责 ConversationList 主列表部分的渲染工作。
作为包裹层默认渲染 Context 中计算好的当前会话列表显示数据 filteredAndSortedConversationList

Props

参数名
类型
默认值
说明
children
ReactNode
-
自定义会话列表内容区域组件。
<ConversationList> 中使用时,会默认传入 filteredAndSortedConversationList 遍历的 <Preview> 列表。
empty
Boolean
false
空会话列表标识位, 在 <ConversationList> 中使用时,会判断filteredAndSortedConversationList.length === 0 并传入。
loading
Boolean
false
会话列表加载中标识位,在 <ConversationList> 中使用时,使用 useConversationList() 获取 isLoading 并传入。
error
Boolean
false
会话列表加载错误标识位,在 <ConversationList> 中使用时,使用 useConversationList() 获取 isLoadError 并传入。
PlaceholderEmptyList
ReactNode
<PlaceHolder type={PlaceHolderTypes.NO_CONVERSATIONS} />
自定义会话列表为空时的占位元素。
PlaceholderLoading
ReactNode
<PlaceHolder type={PlaceHolderTypes.LOADING} />
自定义会话列表加载中的占位元素。
PlaceholderLoadError
ReactNode
<PlaceHolder type={PlaceHolderTypes.WRONG} />
自定义会话列表加载错误时的占位元素。
className
String
-
指定根元素类的 CSS 自定义名称。
style
React.CSSProperties
-
指定根元素样式的自定义样式。

基础定制

List 组件不同状态 UI 效果如下,在 ConversationList 内部已处理好每种状态的触发时机。
同时,您可以通过自定义传入 emptyloadingerror 来控制组件状态。
import { ConversationList, ConversationListContent } from '@tencentcloud/chat-uikit-react';
import type { ConversationListContentProps } from '@tencentcloud/chat-uikit-react';

const CustomConversationListContent = (props: ConversationListContentProps) => {
return <ConversationListContent {...props} loading={true} />;
};

<ConversationList List={CustomConversationListContent} />
default
empty={true}
loading={true}
error={true}













自定义 ConversationPreview

详情请参见 ConversationPreview 章节。
<ConversationList ConversationPreview={CustomConversationPreview} />

自定义 ConversationActions

详情请参见 ConversationActions 章节。
<ConversationList ConversationActions={CustomConversationActions} />

自定义 ConversationSearch

详情请参见 ConversationSearch 章节。
<ConversationList ConversationSearch={CustomConversationSearch} />

自定义 ConversationCreate

<ConversationList ConversationCreate={CustomConversationCreate} />

自定义 Avatar

<ConversationList Avatar={CustomAvatar} />

Props

参数名
类型
默认值
说明
enableSearch
Boolean
true
控制会话搜索功能是否显示。
enableCreate
Boolean
true
控制创建会话功能是否显示。
enableActions
Boolean
true
控制会话操作功能是否显示。
actionsConfig
ConversationActionsConfig
-
用于自定义会话操作配置。
Header
ReactElement
Header
自定义 Header 组件。
List
ReactElement
List
自定义会话列表组件。
Preview
ReactElement
自定义会话预览组件。
ConversationCreate
ReactElement
ConversationCreate
自定义创建会话组件。
ConversationSearch
ReactElement
自定义会话搜索组件。
ConversationActions
ReactElement
自定义会话操作组件。
Avatar
ReactElement
Avatar
自定义头像组件。
PlaceholderEmptyList
ReactNode
<PlaceHolder type={PlaceHolderTypes.NO_CONVERSATIONS} />
自定义会话列表为空时的占位元素。
PlaceholderLoading
ReactNode
<PlaceHolder type={PlaceHolderTypes.LOADING} />
自定义会话列表加载中的占位元素。
PlaceholderLoadError
ReactNode
<PlaceHolder type={PlaceHolderTypes.WRONG} />
自定义会话列表加载错误时的占位元素。
filter
(conversationList: ConversationModel[]) => ConversationModel[]
-
用于筛选会话列表的函数。
sort
(conversationList: ConversationModel[]) => ConversationModel[]
-
用于排序会话列表的函数。
onConversationSelect
(conversation: ConversationModel) => void;
-
点击会话后的回调函数,参数为所点击的会话对象。
onBeforeCreateConversation
(params: CreateParams) => CreateParams;
-
创建会话前执行的自定义操作,参数为创建会话所需的参数。
onConversationCreate
(conversation: ConversationModel) => void;
-
会话创建后的回调函数,参数为创建的会话对象。
className
String
-
指定根元素类的 CSS 自定义名称。
style
React.CSSProperties
-
指定根元素样式的自定义样式。




帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈