Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b322c57
Add Providers API reference for Chat React SDK
m-hulbert Mar 12, 2026
3b201ad
Add useChatClient hook API reference
m-hulbert Mar 12, 2026
dec57f9
Add useChatConnection hook API reference
m-hulbert Mar 12, 2026
087105a
Add useRoom hook API reference
m-hulbert Mar 12, 2026
73cfb2d
Add useMessages hook API reference
m-hulbert Mar 12, 2026
b0e001b
Add usePresence hook API reference
m-hulbert Mar 12, 2026
0bfa6f2
Add usePresenceListener hook API reference
m-hulbert Mar 12, 2026
872091e
Add useOccupancy hook API reference
m-hulbert Mar 12, 2026
7bce2cb
Add useTyping hook API reference
m-hulbert Mar 12, 2026
b748739
Add useRoomReactions hook API reference
m-hulbert Mar 12, 2026
e9feb4e
Add React hooks section to Chat navigation
m-hulbert Mar 12, 2026
15ddaf8
Update Chat API index to link to React hook references
m-hulbert Mar 12, 2026
797ae27
fixup! Add Providers API reference for Chat React SDK
m-hulbert Mar 17, 2026
ff16353
fixup! Add useMessages hook API reference
m-hulbert Mar 17, 2026
a8b18c3
fix: update ErrorInfo.cause to type ErrorInfo in chat JS refs
m-hulbert Mar 17, 2026
b15e2f4
fix: add clipped property to Chat JS API refs on message summaries
m-hulbert Mar 24, 2026
fb8ba73
fixup! Add useMessages hook API reference
m-hulbert Mar 24, 2026
693d091
fixup! Add useMessages hook API reference
m-hulbert Mar 27, 2026
2999ac7
fixup! Add useChatClient hook API reference
m-hulbert Mar 27, 2026
bea5741
fixup! Add usePresence hook API reference
m-hulbert Mar 27, 2026
4ea209f
fixup! Add useRoomReactions hook API reference
m-hulbert Mar 27, 2026
2cf4cc8
fixup! Add usePresenceListener hook API reference
m-hulbert Mar 27, 2026
4a0b435
fixup! Add Providers API reference for Chat React SDK
m-hulbert Mar 27, 2026
856bc7c
fixup! Add useTyping hook API reference
m-hulbert Mar 27, 2026
29fcd77
fix: rename typing event types and add deprecated properties to Chat …
m-hulbert Mar 27, 2026
7651f94
fix: add totalClientIds and fix clipped table formatting in Chat JS A…
m-hulbert Mar 27, 2026
b30ffb3
fix: add encoding property to PresenceMember in Chat JS API refs
m-hulbert Mar 27, 2026
fb45599
fixup! Add useTyping hook API reference
m-hulbert Mar 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/data/nav/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,49 @@ export default {
],
},
{
link: 'https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/modules/chat-react.html',
name: 'React SDK',
external: true,
name: 'React',
pages: [
{
link: '/docs/chat/api/react/providers',
name: 'Providers',
},
{
link: '/docs/chat/api/react/use-chat-client',
name: 'useChatClient',
},
{
link: '/docs/chat/api/react/use-chat-connection',
name: 'useChatConnection',
},
{
link: '/docs/chat/api/react/use-room',
name: 'useRoom',
},
{
link: '/docs/chat/api/react/use-messages',
name: 'useMessages',
},
{
link: '/docs/chat/api/react/use-presence',
name: 'usePresence',
},
{
link: '/docs/chat/api/react/use-presence-listener',
name: 'usePresenceListener',
},
{
link: '/docs/chat/api/react/use-occupancy',
name: 'useOccupancy',
},
{
link: '/docs/chat/api/react/use-typing',
name: 'useTyping',
},
{
link: '/docs/chat/api/react/use-room-reactions',
name: 'useRoomReactions',
},
],
},
{
link: 'https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/docs/chat/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This section of the documentation contains the API references for Ably Chat.
The following API references are available:

* [JavaScript](/docs/chat/api/javascript/chat-client)
* [React Hooks](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/modules/chat-react.html)
* [React](/docs/chat/api/react/providers)
* [Kotlin (JVM & Android)](https://sdk.ably.com/builds/ably/ably-chat-kotlin/main/dokka/)
* [Swift](https://sdk.ably.com/builds/ably/ably-chat-swift/main/AblyChat/documentation/ablychat/)

Expand Down
2 changes: 1 addition & 1 deletion src/pages/docs/chat/api/javascript/chat-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ A standardized, generic Ably error object that contains an Ably-specific status
| code | Ably-specific error code. | Number |
| statusCode | HTTP status code corresponding to this error, where applicable. | Number |
| message | Additional information about the error. | String |
| cause | The underlying cause of the error, where applicable. | String, ErrorInfo, or Error |
| cause | The underlying cause of the error, where applicable. | ErrorInfo |
| detail | Optional map of string key-value pairs containing structured metadata associated with the error. | `Record<string, string>` or Undefined |

</Table>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/docs/chat/api/javascript/message-reactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ The `subscribe()` method takes the following parameters:
| --- | --- | --- |
| total | The total number of clients who have reacted with this name. | Number |
| clientIds | A list of the client IDs of all clients who have reacted with this name. | String[] |
| clipped | Whether the list of client IDs has been clipped due to exceeding the maximum allowed. | Boolean |

</Table>

Expand All @@ -191,7 +192,9 @@ The `subscribe()` method takes the following parameters:
| --- | --- | --- |
| total | The total count of reactions with this name across all clients. | Number |
| clientIds | A map of client ID to the count each client has contributed. | `Record<string, number>` |
| totalClientIds | The total number of distinct client IDs in the map. Equal to the length of `clientIds` if `clipped` is `false`. | Number |
| totalUnidentified | The total count from unidentified clients not included in `clientIds`. | Number |
| clipped | Whether the list of client IDs has been clipped due to exceeding the maximum allowed. | Boolean |

</Table>

Expand Down
3 changes: 3 additions & 0 deletions src/pages/docs/chat/api/javascript/message.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The `Message` interface has the following properties:
| --- | --- | --- |
| total | The total number of clients who have reacted with this name. | Number |
| clientIds | A list of the client IDs of all clients who have reacted with this name. | String[] |
| clipped | Whether the list of client IDs has been clipped due to exceeding the maximum allowed. | Boolean |

</Table>

Expand All @@ -98,7 +99,9 @@ The `Message` interface has the following properties:
| --- | --- | --- |
| total | The total count of reactions with this name across all clients. | Number |
| clientIds | A map of client ID to the count each client has contributed. | `Record<string, number>` |
| totalClientIds | The total number of distinct client IDs in the map. Equal to the length of `clientIds` if `clipped` is `false`. | Number |
| totalUnidentified | The total count from unidentified clients not included in `clientIds`. | Number |
| clipped | Whether the list of client IDs has been clipped due to exceeding the maximum allowed. | Boolean |

</Table>

Expand Down
1 change: 1 addition & 0 deletions src/pages/docs/chat/api/javascript/presence.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ The `subscribe()` method takes the following parameters:
| connectionId | The connection ID of the present user. | String |
| data | The presence data associated with the user. | <Table id='PresenceData'/> or Undefined |
| extras | Additional data included with the presence message. | JsonObject or Undefined |
| encoding | The encoding applied to the presence data, if any. Contains remaining transformations not yet applied to the `data` property. | String or Undefined |
| updatedAt | When this presence state was last updated. | Date |

</Table>
Expand Down
10 changes: 6 additions & 4 deletions src/pages/docs/chat/api/javascript/typing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The `Typing` interface has the following properties:
| Property | Description | Type |
| --- | --- | --- |
| currentTypers | The set of users currently typing in the room, with associated metadata such as user claims. | <Table id='TypingMember'/> |
| current | **Deprecated.** Use `currentTypers` instead. The set of client IDs currently typing. | `Set<string>` |

</Table>

Expand Down Expand Up @@ -106,17 +107,18 @@ The `subscribe()` method takes the following parameters:

| Parameter | Required | Description | Type |
| --- | --- | --- | --- |
| listener | Required | Callback invoked when the typing state changes. | <Table id='TypingEvent'/> |
| listener | Required | Callback invoked when the typing state changes. | <Table id='TypingSetEvent'/> |

</Table>

<Table id='TypingEvent' hidden>
<Table id='TypingSetEvent' hidden>

| Property | Description | Type |
| --- | --- | --- |
| type | The type of the event. Always `SetChanged`. | <Table id='TypingSetEventType'/> |
| currentTypers | The set of users currently typing, with associated metadata such as user claims. | <Table id='TypingMember'/> |
| change | Information about the specific change that triggered this event. | <Table id='TypingChange'/> |
| currentlyTyping | **Deprecated.** Use `currentTypers` instead. The set of client IDs currently typing. | `Set<string>` |
| change | Information about the specific change that triggered this event. | <Table id='TypingSetEvent.change'/> |

</Table>

Expand All @@ -128,7 +130,7 @@ The `subscribe()` method takes the following parameters:

</Table>

<Table id='TypingChange' hidden>
<Table id='TypingSetEvent.change' hidden>

| Property | Description | Type |
| --- | --- | --- |
Expand Down
195 changes: 195 additions & 0 deletions src/pages/docs/chat/api/react/providers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
---
title: Providers
meta_description: "API reference for the ChatClientProvider and ChatRoomProvider components in the Ably Chat React SDK."
meta_keywords: "Ably Chat SDK, React, ChatClientProvider, ChatRoomProvider, providers, context, hooks"
---

The Ably Chat React SDK provides two context providers that supply chat functionality to your component tree. All chat hooks must be used within these providers.

An API key is required to authenticate with Ably. API keys are used either to authenticate directly with Ably using basic authentication, or to generate tokens for untrusted clients using [JWT authentication](/docs/auth/token#jwt). Authenticate an `Ably.Realtime` Pub/Sub client and then pass it to the `ChatClientProvider`.

<Aside data-type='important'>
Basic authentication should never be used on the client-side in production, as it exposes your Ably API key. Instead, use JWT authentication.
</Aside>

<Code>
```react
import * as Ably from 'ably';
import { ChatClient } from '@ably/chat';
import { ChatClientProvider, ChatRoomProvider } from '@ably/chat/react';

const realtimeClient = new Ably.Realtime({ key: '{{API_KEY}}', clientId: 'my-client-id' });
const chatClient = new ChatClient(realtimeClient);

function App() {
return (
<ChatClientProvider client={chatClient}>
<ChatRoomProvider name="my-room">
{/* Chat hooks can be used here */}
</ChatRoomProvider>
</ChatClientProvider>
);
}
```
</Code>

<Aside data-type='important'>
Create the `ChatClient` and underlying `Ably.Realtime` client outside of React components to avoid creating duplicate connections on re-renders.
</Aside>

## ChatClientProvider <a id="chatClientProvider"/>

Provides a `ChatClient` instance to all descendant components via React context. All chat hooks, including [`useChatClient`](/docs/chat/api/react/use-chat-client) and [`useChatConnection`](/docs/chat/api/react/use-chat-connection), require this provider to be present in the component tree.

The `client` property should be memoized to prevent unnecessary context updates. The provider manages room reference counting internally, only detaching rooms when no references remain.

### Properties <a id="chatClientProvider-properties"/>

<Table id='ChatClientProviderProps'>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| client | Required | An instance of the ChatClient. | ChatClient |
| children | Optional | Child components that will have access to the chat client context. | ReactNode or ReactNode[] |

</Table>

## ChatRoomProvider <a id="chatRoomProvider"/>

Provides room context to descendant components. All room-level hooks such as [`useMessages`](/docs/chat/api/react/use-messages), [`usePresence`](/docs/chat/api/react/use-presence), and [`useTyping`](/docs/chat/api/react/use-typing) require this provider.

The provider automatically handles room attachment and detachment. Multiple providers for the same room with the same options share the same underlying room instance through reference counting.

### Properties <a id="chatRoomProvider-properties"/>

<Table id='ChatRoomProviderProps'>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| name | Required | The name of the room. | String |
| options | Optional | Options to use when creating the room. Must be memoized to prevent unnecessary room recreations. Room options are immutable after creation; using different options for the same room name will reject with a `RoomExistsWithDifferentOptions` error. | <Table id='RoomOptions'/> |
| children | Optional | Child components that will have access to the room context. | ReactNode or ReactNode[] |

</Table>

<Table id='RoomOptions' hidden>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| typing | Optional | Configuration for typing indicators. | <Table id='TypingOptions'/> |
| presence | Optional | Configuration for presence events. | <Table id='PresenceOptions'/> |
| occupancy | Optional | Configuration for occupancy events. | <Table id='OccupancyOptions'/> |
| messages | Optional | Configuration for message reactions. | <Table id='MessagesOptions'/> |

</Table>

<Table id='TypingOptions' hidden>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| heartbeatThrottleMs | Optional | Minimum time in milliseconds between consecutive typing started events. The first call emits immediately; later calls are no-ops until the interval has elapsed. Calling typing.stop resets the interval. The default value is `10000`. | Number |

</Table>

<Table id='PresenceOptions' hidden>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| enableEvents | Optional | Whether the client receives presence events from the server. Can be disabled if presence is used but this client does not need the messages. The default value is `true`. | Boolean |

</Table>

<Table id='OccupancyOptions' hidden>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| enableEvents | Optional | Whether to receive occupancy events. Enabling this increases message volume as the server sends additional updates for occupancy changes. The default value is `false`. | Boolean |

</Table>

<Table id='MessagesOptions' hidden>

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| rawMessageReactions | Optional | Whether to receive raw individual message reactions from the realtime channel. Reaction summaries remain available regardless of this setting. The default value is `false`. | Boolean |
| defaultMessageReactionType | Optional | The default message reaction type for sending reactions. Individual types can still be specified via the send method parameter. The default value is `Distinct`. | <Table id='MessageReactionType'/> |

</Table>

<Table id='MessageReactionType' hidden>

| Value | Description |
| --- | --- |
| Distinct | Allows at most one reaction of each type per client per message. Duplicates are not counted in the summary. Similar to reactions on Slack. The value is `distinct`. |
| Multiple | Allows any number of reactions, including repeats, counted in the summary. The reaction payload includes a count. Similar to the clap feature on Medium. The value is `multiple`. |
| Unique | Allows at most one reaction per client per message. If a client reacts again, only the second reaction is counted. Similar to reactions on iMessage or WhatsApp. The value is `unique`. |

</Table>

## ErrorInfo <a id="errorInfo"/>

A standardized, generic Ably error object that contains an Ably-specific status code, and a generic HTTP status code. All errors returned from Ably are compatible with the `ErrorInfo` structure.

<Table id='ErrorInfo'>

| Property | Description | Type |
| --- | --- | --- |
| code | Ably-specific error code. | Number |
| statusCode | HTTP status code corresponding to this error, where applicable. | Number |
| message | Additional information about the error. | String |
| cause | The underlying cause of the error, where applicable. | [ErrorInfo](#errorInfo) or Undefined |
| detail | Optional map of string key-value pairs containing structured metadata associated with the error. | `Record<string, string>` or Undefined |

</Table>

## DiscontinuityListener <a id="discontinuityListener"/>

A callback to detect and respond to discontinuities in the event stream. Discontinuities occur when the client may have missed events due to connectivity issues.

<Table id='DiscontinuityListener'>

| Parameter | Description | Type |
| --- | --- | --- |
| error | An error providing context about why the discontinuity occurred. | [ErrorInfo](#errorInfo) |

</Table>

## Example

<Code>
```react
import * as Ably from 'ably';
import { ChatClient } from '@ably/chat';
import { ChatClientProvider, ChatRoomProvider } from '@ably/chat/react';
import { useMemo } from 'react';

// Create clients outside of components
// Use JWT token authentication in production
const realtimeClient = new Ably.Realtime({
key: '{{API_KEY}}',
clientId: 'user-123'
});
const chatClient = new ChatClient(realtimeClient);

function App() {
// Memoize room options to prevent unnecessary recreations
const roomOptions = useMemo(() => ({
typing: { heartbeatThrottleMs: 5000 },
occupancy: { enableEvents: true },
}), []);

return (
<ChatClientProvider client={chatClient}>
<ChatRoomProvider name="my-room" options={roomOptions}>
<ChatRoom />
</ChatRoomProvider>
</ChatClientProvider>
);
}

function ChatRoom() {
// All chat hooks can be used here
return <div>Chat room content</div>;
}
```
</Code>
Loading