LiveKit docs › Hooks › useDataChannel

---

# useDataChannel

The `useDataChannel` hook returns the ability to send and receive messages. Pass an optional `topic` to narrow down which messages are returned in the messages array.

## Import

```typescript
import { useDataChannel } from "@livekit/components-react";

```

## Remarks

There is only one data channel. Passing a `topic` does not open a new data channel. It is only used to filter out messages with no or a different `topic`.

## Usage

### Example 1

```tsx
// Send messages to all participants via the 'chat' topic.
const { message: latestMessage, send } = useDataChannel("chat", (msg) =>
  console.log("message received", msg)
);

```

### Example 2

```tsx
// Receive all messages (no topic filtering)
const { message: latestMessage, send } = useDataChannel((msg) =>
  console.log("message received", msg)
);

```

## Properties

- **`topic`** _(T)_: 

- **`onMessage`** _((msg: ReceivedDataMessage<T>) => void)_ (optional): 

## Returns

```typescript
UseDataChannelReturnType<T>;

```

---

This document was rendered at 2026-06-07T11:34:12.839Z.
For the latest version of this document, see [https://docs.livekit.io/reference/components/react/hook/usedatachannel.md](https://docs.livekit.io/reference/components/react/hook/usedatachannel.md).

To explore all LiveKit documentation, see [llms.txt](https://docs.livekit.io/llms.txt).