Skip to content

Commit edca8fa

Browse files
committed
fixup! Add Chat's React Native getting started guide
1 parent dbc3fdb commit edca8fa

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/pages/docs/chat/getting-started/react-native.mdx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,7 @@ Update your `ChatApp()` component first by wrapping the contents of the return w
282282
```react
283283
function ChatApp() {
284284
return (
285-
<ChatRoomProvider
286-
name="my-first-room"
287-
release={true}
288-
attach={true}
289-
>
285+
<ChatRoomProvider name="my-first-room">
290286
<KeyboardAvoidingView
291287
className="flex-1"
292288
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
@@ -339,7 +335,7 @@ function ChatBox() {
339335
const [inputValue, setInputValue] = useState('');
340336
const [messages, setMessages] = useState<Message[]>([]);
341337
342-
const {send} = useMessages({
338+
const {sendMessage} = useMessages({
343339
listener: (event: ChatMessageEvent) => {
344340
const message = event.message;
345341
switch (event.type) {
@@ -356,7 +352,7 @@ function ChatBox() {
356352
357353
const handleSend = () => {
358354
if (!inputValue.trim()) return;
359-
send({text: inputValue.trim()}).catch((err) =>
355+
sendMessage({text: inputValue.trim()}).catch((err) =>
360356
console.error('Error sending message', err),
361357
);
362358
setInputValue('');
@@ -405,11 +401,7 @@ Add `ChatBox` component to your `ChatApp` component:
405401
// Update ChatApp to include ChatBox
406402
function ChatApp() {
407403
return (
408-
<ChatRoomProvider
409-
name="my-first-room"
410-
release={true}
411-
attach={true}
412-
>
404+
<ChatRoomProvider name="my-first-room">
413405
<KeyboardAvoidingView
414406
className="flex-1"
415407
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
@@ -455,9 +447,9 @@ You'll see the message in your app's chat box UI. If you have sent a message via
455447

456448
## Step 5: Edit a message <a id="step-5"/>
457449

458-
If your client makes a typo, or needs to update their original message then they can edit it. To do this, you can extend the functionality of the `ChatBox` component to allow updating of messages. The `useMessages()` hook exposes the [`update()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#update) method of the Chat SDK [messages](/docs/chat/rooms/messages?lang=react) feature.
450+
If your client makes a typo, or needs to update their original message then they can edit it. To do this, you can extend the functionality of the `ChatBox` component to allow updating of messages. The `useMessages()` hook exposes the [`updateMessage()`](https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/interfaces/chat-js.Messages.html#update) method of the Chat SDK [messages](/docs/chat/rooms/messages?lang=react) feature.
459451

460-
Expose the `update()` method from the `useMessages()` hook and then add a method to the `ChatBox` component to handle the edit action like so:
452+
Expose the `updateMessage()` method from the `useMessages()` hook and then add a method to the `ChatBox` component to handle the edit action like so:
461453

462454
<Code>
463455
```react
@@ -483,7 +475,7 @@ function ChatBox() {
483475
return;
484476
}
485477
486-
update(editingMessage.serial, {text: editText.trim()}, {description: "Message update by user"})
478+
updateMessage(editingMessage.serial, {text: editText.trim()}, {description: "Message update by user"})
487479
.then((updatedMsg: Message) => {
488480
console.log('Message updated:', updatedMsg);
489481
setEditModalVisible(false);
@@ -499,7 +491,7 @@ function ChatBox() {
499491
});
500492
501493
console.log('Update function completed');
502-
}, [editingMessage, editText, update]);
494+
}, [editingMessage, editText, updateMessage]);
503495
504496
const handleChange = (newValue: string) => {
505497
setInputValue(newValue);
@@ -606,7 +598,7 @@ Update the listener provided to the `useMessages()` hook to handle the `ChatMess
606598
<Code>
607599
```react
608600
// ChatApp.tsx - Replace the useMessages hook with the following:
609-
const {send, update} = useMessages({
601+
const {sendMessage, updateMessage} = useMessages({
610602
listener: (event: ChatMessageEvent) => {
611603
const message = event.message;
612604
switch (event.type) {
@@ -659,7 +651,7 @@ In your `ChatApp.tsx` file, add the following `useEffect` to your `ChatBox` comp
659651
function ChatBox() {
660652
// ...existing code...
661653
662-
const {send, update, historyBeforeSubscribe} = useMessages({
654+
const {sendMessage, updateMessage, historyBeforeSubscribe} = useMessages({
663655
// ...existing code...
664656
});
665657
@@ -837,7 +829,7 @@ In your `ChatApp.tsx` file, add a new component called `ReactionComponent`, like
837829
function ReactionComponent() {
838830
const reactions = ['👍', '❤️', '💥', '🚀', '👎', '💔'];
839831
const [roomReactions, setRoomReactions] = useState<Reaction[]>([]);
840-
const {send} = useRoomReactions({
832+
const {sendReaction} = useRoomReactions({
841833
listener: (reactionEvent) => {
842834
setRoomReactions((prev) => [...prev, reactionEvent.reaction]);
843835
},
@@ -851,7 +843,7 @@ function ReactionComponent() {
851843
<TouchableOpacity
852844
key={reaction}
853845
onPress={() =>
854-
send({name: reaction}).catch((err) =>
846+
sendReaction({name: reaction}).catch((err) =>
855847
console.error('Error sending reaction', err),
856848
)
857849
}

0 commit comments

Comments
 (0)