Skip to content

[DX-629] Add Chat React API references#3272

Open
m-hulbert wants to merge 17 commits intomainfrom
dx-629-chat-react-api-refs
Open

[DX-629] Add Chat React API references#3272
m-hulbert wants to merge 17 commits intomainfrom
dx-629-chat-react-api-refs

Conversation

@m-hulbert
Copy link
Contributor

Description

This PR adds an API reference for Chat in React using the new NestedTable and MethodSignature components. It should have parity with the TypeDoc references.

There is 1 commit per file, however I haven't yet updated the references in the conceptual content to point to these references yet to keep this PR smaller for review feedback. I will add that as a final commit once we are happy with this content.

Checklist

m-hulbert and others added 12 commits March 12, 2026 19:24
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@m-hulbert m-hulbert self-assigned this Mar 12, 2026
@m-hulbert m-hulbert added the review-app Create a Heroku review app label Mar 12, 2026
@ably-ci ably-ci temporarily deployed to ably-docs-dx-629-chat-r-bl9cry March 12, 2026 19:26 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0733a5aa-1dce-4525-acc8-64a9d14fe914

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dx-629-chat-react-api-refs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@m-hulbert m-hulbert requested a review from splindsay-92 March 13, 2026 08:50
Copy link
Contributor

@splindsay-92 splindsay-92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things so far, but mostly looks good!

@m-hulbert m-hulbert temporarily deployed to ably-docs-dx-629-chat-r-bl9cry March 17, 2026 18:29 Inactive
@m-hulbert m-hulbert temporarily deployed to ably-docs-dx-629-chat-r-bl9cry March 17, 2026 18:30 Inactive
@m-hulbert m-hulbert requested a review from splindsay-92 March 17, 2026 18:32
@m-hulbert m-hulbert requested a review from splindsay-92 March 24, 2026 16:35

// Create clients outside of components
const realtimeClient = new Ably.Realtime({
key: '{{API_KEY}}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a short comment like // Use JTW token authentication in production?

},
});

return <button onClick={() => sendMessage({ text: 'Hello!' })}>Send</button>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since sendMessage is async, the more correct way to do this would be define a handler to capture any error state. E.g.

const handleSend = () => {
    sendMessage().catch((error: unknown) => {
      console.error('Failed to send message', error);
    });
  };

The above still works fine though, and errors would still be logged as SDK logs regardless (so you'd see them in the console), so I'll defer to you on if you think this really needs to be that verbose or if the simplicity is better and gets the job done here :)

function ChatMessages() {
const [messages, setMessages] = useState([]);

const { sendMessage, updateMessage, deleteMessage, history, sendReaction } = useMessages({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my opinion, but historyBeforeSubscribe is preferable over history, but again, it's not incorrect :)

case ChatMessageEventType.Updated:
case ChatMessageEventType.Deleted:
return prev.map((msg) =>
msg.serial === event.message.serial ? event.message : msg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be checking the version serial before doing any sort of swap. Also, we have the .with() function on a message to make this very easy too :)
msg.serial === event.message.serial ? msg.with(event.message) : msg

meta_keywords: "Ably Chat SDK, React, useChatClient, hooks, chat client, clientId"
---

The `useChatClient` hook provides access to the `ChatClient` instance supplied by the [`ChatClientProvider`](/docs/chat/api/react/providers#chatClientProvider). It automatically monitors the `clientId` and refreshes when connection state changes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really the case, it provides access to only the clientId, not the instance itself.

| Property | Required | Description | Type |
| --- | --- | --- | --- |
| name | Required | The name of the reaction, typically an emoji or identifier. | String |
| metadata | Optional | Additional metadata to include with the reaction. | JsonObject |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| metadata | Optional | Additional metadata to include with the reaction. | JsonObject |
| metadata | Optional | Additional metadata to include with the reaction. | RoomReactionMetadata |

| --- | --- | --- | --- |
| name | Required | The name of the reaction, typically an emoji or identifier. | String |
| metadata | Optional | Additional metadata to include with the reaction. | JsonObject |
| headers | Optional | Additional information in Ably message extras, usable for features like referencing external resources. | Headers |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| headers | Optional | Additional information in Ably message extras, usable for features like referencing external resources. | Headers |
| headers | Optional | Additional information in Ably message extras, usable for features like referencing external resources. | RoomReactionHeaders |

| 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 |
| updatedAt | When this presence state was last updated. | Date |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoding should also be mentioned here I think

This hook must be used within a [`ChatRoomProvider`](/docs/chat/api/react/providers#chatRoomProvider).

<Aside data-type='important'>
Avoid using multiple instances of this hook within the same `ChatClientProvider`, as they share the same underlying presence instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Avoid using multiple instances of this hook within the same `ChatClientProvider`, as they share the same underlying presence instance.
Avoid using multiple instances of this hook within the same `ChatRoomProvider`, as they share the same underlying presence instance.


</Table>

<Table id='TypingChange' hidden>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a TypingChange event, but the properties here exist on the change field of the TypingSetEvent, is that what's meant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-app Create a Heroku review app

Development

Successfully merging this pull request may close these issues.

3 participants