Overview
TheChat component provides a fully functional real-time chat interface that synchronizes messages across all connected users. It includes a header, message list, input field, and can be minimized. All UI elements are customizable through the components prop.
Perfect for: Team communication, customer support chat, collaborative comments, real-time discussions, and any application requiring instant messaging.
Basic Usage
Props
string
required
Unique identifier for the chat session. All users with the same key will share the same chat
string | React.ReactElement
default:"'Group Chat'"
Display name shown in the chat header
boolean
default:"false"
Whether to hide the entire chat component when not connected to a session
ChatComponents
Custom components to override default chat UI elements
ChatComponents Interface
Thecomponents prop allows you to customize every part of the chat interface:
Examples
Basic Team Chat
Simple chat implementation for team communication:Custom Chat Header
Customize the chat header with additional information:Custom Message Display
Create custom message bubbles with enhanced styling:Custom Input with Rich Features
Enhanced chat input with additional features:Support Chat System
Build a customer support chat with custom components:Multi-Channel Chat
Create a chat system with multiple channels:Chat with File Sharing Simulation
Enhanced chat with simulated file sharing:Moderated Chat
Chat with message moderation features:Built-in Features
Message Structure
Each message contains:Auto-scrolling
Messages automatically scroll to the bottom when new messages arrive.Minimize/Expand
The chat can be minimized to save screen space and expanded when needed.Connection Awareness
The chat automatically handles disconnection states with appropriate UI feedback.Styling
The Chat component includes default CSS classes that you can customize:Best Practices
Performance
Accessibility
User Experience
Common Patterns
- Sidebar Chat: Fixed position chat for ongoing communication
- Modal Chat: Chat opened in a modal dialog
- Multi-channel: Different chat rooms for different topics
- Support Chat: Customer service with agent identification
- Threaded Chat: Replies to specific messages (requires custom implementation)
Related Hooks
useChat- The underlying hook powering the Chat componentuseConnectedUsers- Get connected users for chat featuresuseMyId- Identify current user in messagesuseNicknames- User display names