Skip to content

Commit

Permalink
Merge pull request #434 from ably/docs/update-message-type
Browse files Browse the repository at this point in the history
Docs: Fixed a small typing issue in the react docs for updates.
  • Loading branch information
splindsay-92 authored Dec 10, 2024
2 parents 3c051a3 + 8c0eac5 commit 6d1b04a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,26 +222,32 @@ import { Message } from '@ably/chat';

const MyComponent = () => {
const { send, get, update, deleteMessage } = useMessages();
const [message, setMessage] = useState<Message>();
const [messages, setMessages] = useState<Message[]>([]);
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) => {
const newText = prompt('Enter new text');
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 (
Expand Down

0 comments on commit 6d1b04a

Please sign in to comment.