chilly-motorcycle-32290
08/03/2025, 4:35 AMtall-airline-16756
08/03/2025, 4:35 AMtall-airline-16756
08/03/2025, 4:35 AMuseChat hook or the pre-built Chat component:
• Using the useChat Hook: function ChatComponent() {
const { chatMessages, send, isSending } = useChat();
return (
{chatMessages.map((msg) => (
{msg.from?.identity}: {msg.message}
))}
);
}
◦ The useChat hook provides chatMessages, send, and isSending properties.
◦ `chatMessages`: An array of received chat messages.
◦ `send`: A function to send a new message.
◦ `isSending`: A boolean indicating if a message is currently being sent.
• Using the Chat Component: import { Chat } from '@livekit/components-react';
import '@livekit/components-styles';
export default function Room() {
return (
);
}
◦ The Chat component provides a pre-built UI for chat functionality.
◦ It includes message display, input field, and send button out-of-the-box.
Let me know if you need help with specific implementation details!
Sources: Add chat to your React app | LiveKit Docs | packages/core/src/observables/dataChannel.tschilly-motorcycle-32290
08/03/2025, 4:40 AMtall-airline-16756
08/03/2025, 4:41 AMuseChat hook:chilly-motorcycle-32290
08/03/2025, 8:40 AMtall-airline-16756
08/03/2025, 8:41 AMuseChat Hook: This one’s perfect if you’re focusing on chat features. It gives you a list of received messages through the chatMessages property, making it super straightforward.
import { useChat } from '@livekit/components-react';
function ChatInterface() {
const { chatMessages } = useChat();
return (
{chatMessages.map((msg, index) => (
{msg.from?.identity}: {msg.message}
))}
);
}
• useDataChannel Hook: This one’s a bit more flexible—it lets you send and receive messages through a data channel, whether you want to filter by topic or not. Great if you need more control.
import { useDataChannel } from '@livekit/components-react';
function MessageReceiver() {
const { message } = useDataChannel((msg) => {
console.log("Received message:", msg);
});
return (
Latest message: {message?.message}
);
}
So, if you’re building chat-specific stuff, useChat is your friend. But if you want more control over messaging, useDataChannel has got you covered. Feel free to ask if you want me to help you with anything else!