npm create rsbuild@latest
npm i @tencentcloud/chat-uikit-react
SDKAppID, userID, and UserSig. You need to replace them with the relevant information obtained in Step 4.
App.tsx code and replace the original content in App.tsx.App.css code and replace the App.css style file in the same directory.import {UIKitProvider,useLoginState,LoginStatus,ConversationList,Chat,ChatHeader,MessageList,MessageInput,ContactList,ContactInfo,useUIKit,useConversationListState,} from "@tencentcloud/chat-uikit-react";import { useEffect, useState } from "react";import './App.css';function App() {// Language support en-US(default) / zh-CN / ja-JP / ko-KR / zh-TW// Theme supports light(default) / darkreturn (<UIKitProvider theme={'light'} language={'en-US'}><ChatApp /></UIKitProvider>);}function ChatApp() {const [activeTab, setActiveTab] = useState('chats');const { language } = useUIKit();const texts = language === 'zh-CN'? { chats: '会话', contacts: '联系人', emptyTitle: '暂无会话', emptySub: '选择一个会话开始聊天', error: '请检查 SDKAppID, userID, userSig, 通过开发人员工具(F12)查看具体的错误信息', loading: '登录中...' }: { chats: 'Chats', contacts: 'Contacts', emptyTitle: 'No conversation', emptySub: 'Select a conversation to start chatting', error: 'Please check the SDKAppID, userID, and userSig. View the specific error information through the developer tools (F12).', loading: 'Logging in...'};const { status } = useLoginState({SDKAppID: 0, // type: numberuserID: '', // type: stringuserSig: '', // type: string})const { setActiveConversation } = useConversationListState();useEffect(() => {async function init() {// You can switch to another created userIDconst userID = 'administrator';const conversationID = `C2C${userID}`;setActiveConversation(conversationID);}if (status === LoginStatus.SUCCESS) {init();}}, [status]);if (status === LoginStatus.ERROR) {return (<div className="loading-container"><div className="loading-spinner"></div><div className="loading-text">{texts.error}</div></div>)}if (status !== LoginStatus.SUCCESS) {return (<div className="loading-container"><div className="loading-spinner"></div><div className="loading-text">{texts.loading}</div></div>)}return (<div className="chat-app"><ul className="vertical-tabs"><liclassName={`tab-item ${activeTab === 'chats' ? 'active' : ''}`}onClick={() => {setActiveTab('chats')}}>{texts.chats}</li><liclassName={`tab-item ${activeTab === 'contacts' ? 'active' : ''}`}onClick={() => {setActiveTab('contacts')}}>{texts.contacts}</li></ul>{activeTab === 'chats' && (<><ConversationList style={{ flex: '0 0 300px'}}/><ChatclassName="chat-box"PlaceholderEmpty={<div className="empty-chat"><div className="empty-icon">💬</div><div className="empty-title">{texts.emptyTitle}</div><div className="empty-subtitle">{texts.emptySub}</div></div>}><ChatHeader /><MessageList /><MessageInput /></Chat></>)}{activeTab === 'contacts' && (<><ContactList style={{ flex: '0 0 300px'}}/><ContactInfostyle={{ flex: '1'}}onSendMessage={() => {setActiveTab('chats')}}onEnterGroup={() => {setActiveTab('chats')}}/></>)}</div>);}export default App;
body {margin: 0;padding: 20px;font-family: Inter, Avenir, Helvetica, Arial, sans-serif;background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);min-height: 100vh;box-sizing: border-box;}.chat-app {height: calc(100vh - 40px);max-width: 1400px;margin: 0 auto;display: flex;flex-direction: row;background: #ffffff;border-radius: 16px;box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),0 0 0 1px rgba(0, 0, 0, 0.1);overflow: hidden;backdrop-filter: blur(10px);}.vertical-tabs {list-style: none;margin: 0;padding: 0;width: 100px;background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);border-right: 1px solid rgba(0, 0, 0, 0.08);}.tab-item {padding: 16px 20px;cursor: pointer;background: transparent;color: #495057;font-size: 14px;text-align: center;transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);position: relative;}.tab-item::before {content: '';position: absolute;left: 0;top: 50%;transform: translateY(-50%);width: 3px;height: 0;background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);border-radius: 0 3px 3px 0;transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);}.tab-item:hover {background: rgba(102, 126, 234, 0.08);color: #667eea;}.tab-item.active {background: linear-gradient(90deg, rgba(102, 126, 234, 0.15) 0%, rgba(102, 126, 234, 0.05) 100%);color: #667eea;}.tab-item.active::before {height: 60%;}.chat-box {flex: 1;border-left: 1px solid rgba(0, 0, 0, 0.08);}.empty-chat {display: flex;flex: 1;flex-direction: column;align-items: center;justify-content: center;height: 100%;color: #adb5bd;gap: 12px;text-align: center;border-left: 1px solid rgba(0, 0, 0, 0.08);}.empty-icon {font-size: 64px;opacity: 0.3;animation: float 3s ease-in-out infinite;}.empty-title {font-size: 16px;font-weight: 600;color: #6c757d;}.empty-subtitle {font-size: 14px;color: #868e96;}@keyframes float {0%, 100% {transform: translateY(0px);}50% {transform: translateY(-10px);}}.loading-container {display: flex;flex-direction: column;align-items: center;justify-content: center;height: 100vh;background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);gap: 24px;}.loading-spinner {width: 60px;height: 60px;border: 4px solid rgba(255, 255, 255, 0.2);border-top-color: #ffffff;border-radius: 50%;animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);}.loading-text {color: #ffffff;font-size: 18px;font-weight: 500;letter-spacing: 0.5px;animation: pulse 2s ease-in-out infinite;}@keyframes spin {0% {transform: rotate(0deg);}100% {transform: rotate(360deg);}}@keyframes pulse {0%, 100% {opacity: 1;}50% {opacity: 0.6;}}Here is the translation. I have replaced the **Ant Design** example with **Material UI (MUI)**, which is widely used in the international React community.---**Does it support React 17?**React v17.x is currently not supported. We only support React v18.2 or higher.**Can I use third-party component libraries, such as Material UI?**Yes, you can use other libraries for the "glue code" connecting the core components. You can see this in the example below, where `<ChatSetting />` is encapsulated within a Drawer component. However, please note that the internal elements of the core components cannot be modified at this time.```javascriptimport Drawer from '@mui/material/Drawer';import { useState } from 'react';// ... inside your componentconst [isChatSettingShow, setIsChatSettingShow] = useState(false);const onChatSettingClose = () => {setIsChatSettingShow(false);};<Draweranchor="right"open={isChatSettingShow}onClose={onChatSettingClose}>{/* Material UI Drawers wrap content directly */}<h3>Settings</h3><ChatSetting /></Drawer>```tep 3: Obtain SDKAppID, UserID and UserSig###
App.tsx code, the login authentication information is empty. You need to fill in your Tencent Cloud application authentication information in the useLoginState hook, as shown below:Parameter | Type | Note |
userID | String | Unique identifier of the user, defined by you, it is allowed to contain only upper and lower case letters (a-z, A-Z), numbers (0-9), underscores, and hyphens. |
SDKAppID | Number | |
SDKSecretKey | String | |
userSig | String | A security protection signature used for user login authentication to confirm the user's identity and prevent malicious attackers from stealing your cloud service usage rights. |
genTestUserSig (Refer to Step 3.2) function in the debug file to generate a 'userSig'. In this method, SDKSecretKey is vulnerable to decompilation and reverse engineering. Once your key is leaked, attackers can steal your Tencent Cloud traffic.


npm run dev
userID corresponds to a userSig, for more information, see Generating UserSig.
<ChatSetting /> is encapsulated within a Drawer component. However, please note that the internal elements of the core components cannot be modified at this time.import Drawer from '@mui/material/Drawer';import { useState } from 'react';// ... inside your componentconst [isChatSettingShow, setIsChatSettingShow] = useState(false);const onChatSettingClose = () => {setIsChatSettingShow(false);};<Draweranchor="right"open={isChatSettingShow}onClose={onChatSettingClose}>{/* Material UI Drawers wrap content directly */}<h3>Settings</h3><ChatSetting /></Drawer>
Feedback