diff --git a/src/react/README.md b/src/react/README.md index 97455c4b..b9add4ab 100644 --- a/src/react/README.md +++ b/src/react/README.md @@ -222,18 +222,22 @@ import { Message } from '@ably/chat'; const MyComponent = () => { const { send, get, update, deleteMessage } = useMessages(); - const [message, setMessage] = useState(); + const [messages, setMessages] = useState([]); const handleGetMessages = () => { // fetch the last 3 messages, oldest to newest get({ limit: 3, orderBy: OrderBy.oldestFirst }).then((result) => console.log('Previous messages: ', result.items)); }; const handleMessageSend = () => { - send({ text: 'Hello, World!' }).then((sentMessage) => setMessage(sentMessage)); + send({ text: 'Hello, World!' }).then((sentMessage) => + setMessages((prevMessages) => [...prevMessages, sentMessage]), + ); }; const handleMessageDelete = (message: Message) => { - deleteMessage(message, { description: 'deleted by user' }); + deleteMessage(message, { description: 'deleted by user' }).then((deletedMessage) => + console.log('Deleted message: ', deletedMessage), + ); }; const handleUpdateMessage = (message: Message) => { @@ -241,7 +245,9 @@ const MyComponent = () => { if (!newText) { return; } - update(message, { text: newText }, { description: 'updated by user' }); + update(message, { text: newText }, { description: 'updated by user' }).then((updatedMessage) => + console.log('Updated message: ', updatedMessage), + ); }; return (