Skip to content

Commit 3f4d037

Browse files
authored
improve chat docs (#1091)
1 parent 74d98d3 commit 3f4d037

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

.changeset/nice-dragons-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/components-js-doc": patch
3+
---
4+
5+
improve chat docs

packages/react/src/hooks/useChat.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@ import { useConnectionState } from './useConnectionStatus';
88

99
/**
1010
* The `useChat` hook provides chat functionality for a LiveKit room.
11-
* It returns a simple `send` function to send chat messages and an array of `chatMessages` to hold received messages.
12-
* It also returns a `update` function that allows you to implement message-edit functionality.
11+
*
12+
* @remarks
13+
* Message history is not persisted and will be lost if the component is refreshed.
14+
* You may want to persist message history in the browser, a cache or a database.
15+
*
16+
* @returns An object containing:
17+
* - `chatMessages` - Array of received chat messages
18+
* - `send` - Function to send a new message
19+
* - `isSending` - Boolean indicating if a message is currently being sent
20+
*
21+
* @example
22+
* ```tsx
23+
* function ChatComponent() {
24+
* const { chatMessages, send, isSending } = useChat();
25+
*
26+
* return (
27+
* <div>
28+
* {chatMessages.map((msg) => (
29+
* <div key={msg.timestamp}>
30+
* {msg.from?.identity}: {msg.message}
31+
* </div>
32+
* ))}
33+
* <button disabled={isSending} onClick={() => send("Hello!")}>
34+
* Send Message
35+
* </button>
36+
* </div>
37+
* );
38+
* }
39+
* ```
1340
* @public
1441
*/
1542
export function useChat(options?: ChatOptions) {

packages/react/src/prefabs/Chat.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,29 @@ export interface ChatProps extends React.HTMLAttributes<HTMLDivElement>, ChatOpt
1414
}
1515

1616
/**
17-
* The Chat component adds a basis chat functionality to the LiveKit room. The messages are distributed to all participants
18-
* in the room. Only users who are in the room at the time of dispatch will receive the message.
17+
* The Chat component provides ready-to-use chat functionality in a LiveKit room.
18+
* Messages are distributed to all participants in the room in real-time.
19+
*
20+
* @remarks
21+
* - Only users who are in the room at the time of dispatch will receive messages
22+
* - Message history is not persisted between sessions
23+
* - Requires `@livekit/components-styles` to be imported for styling
1924
*
2025
* @example
2126
* ```tsx
22-
* <LiveKitRoom>
23-
* <Chat />
24-
* </LiveKitRoom>
27+
* import '@livekit/components-styles';
28+
*
29+
* function Room() {
30+
* return (
31+
* <LiveKitRoom data-lk-theme="default">
32+
* <Chat />
33+
* </LiveKitRoom>
34+
* );
35+
* }
2536
* ```
37+
*
38+
* For custom styling, refer to: https://docs.livekit.io/reference/components/react/concepts/style-components/
39+
*
2640
* @public
2741
*/
2842
export function Chat({

0 commit comments

Comments
 (0)