Skip to content

Commit da30fb1

Browse files
bcherrylukasIO
andauthored
Add examples for all useDataChannel usages to the first definition (#1136)
Co-authored-by: lukasIO <[email protected]>
1 parent 7b06bd7 commit da30fb1

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

.changeset/orange-birds-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/components-js-docs": patch
3+
---
4+
5+
Add all examples to the one useDataChannel that gets documented

packages/react/src/hooks/useDataChannel.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ type UseDataChannelReturnType<T extends string | undefined = undefined> = {
1313

1414
/**
1515
* The `useDataChannel` hook returns the ability to send and receive messages.
16-
* By optionally passing a `topic`, you can narrow down which messages are returned in the messages array.
16+
* Pass an optional `topic` to narrow down which messages are returned in the messages array.
17+
*
1718
* @remarks
1819
* There is only one data channel. Passing a `topic` does not open a new data channel.
1920
* It is only used to filter out messages with no or a different `topic`.
@@ -23,23 +24,23 @@ type UseDataChannelReturnType<T extends string | undefined = undefined> = {
2324
* // Send messages to all participants via the 'chat' topic.
2425
* const { message: latestMessage, send } = useDataChannel('chat', (msg) => console.log("message received", msg));
2526
* ```
27+
*
28+
* @example
29+
* ```tsx
30+
* // Receive all messages (no topic filtering)
31+
* const { message: latestMessage, send } = useDataChannel((msg) => console.log("message received", msg));
32+
* ```
33+
*
2634
* @public
2735
*/
2836
export function useDataChannel<T extends string>(
2937
topic: T,
3038
onMessage?: (msg: ReceivedDataMessage<T>) => void,
3139
): UseDataChannelReturnType<T>;
40+
3241
/**
33-
* The `useDataChannel` hook returns the ability to send and receive messages.
34-
* @remarks
35-
* There is only one data channel. Passing a `topic` does not open a new data channel.
36-
* It is only used to filter out messages with no or a different `topic`.
42+
* Overload for `useDataChannel` without a topic. See {@link (useDataChannel:1)} for information and usage examples.
3743
*
38-
* @example
39-
* ```tsx
40-
* // Send messages to all participants
41-
* const { message: latestMessage, send } = useDataChannel('chat', (msg) => console.log("message received", msg));
42-
* ```
4344
* @public
4445
*/
4546
export function useDataChannel(

0 commit comments

Comments
 (0)