Conversation
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>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
splindsay-92
left a comment
There was a problem hiding this comment.
Just a few things so far, but mostly looks good!
|
|
||
| // Create clients outside of components | ||
| const realtimeClient = new Ably.Realtime({ | ||
| key: '{{API_KEY}}', |
There was a problem hiding this comment.
Worth adding a short comment like // Use JTW token authentication in production?
| }, | ||
| }); | ||
|
|
||
| return <button onClick={() => sendMessage({ text: 'Hello!' })}>Send</button>; |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
| | 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 | |
There was a problem hiding this comment.
| | 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 | |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| 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> |
There was a problem hiding this comment.
There isn't a TypingChange event, but the properties here exist on the change field of the TypingSetEvent, is that what's meant?
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