Skip to content

Commit

Permalink
3l Solution 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSimpleDev committed Oct 31, 2024
1 parent 34d7ae9 commit eb84019
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 2-copy-of-code/lesson-03/chatbot.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@
message: inputText,
sender: 'user',
id: crypto.randomUUID()
},
// Another solution is to add the Loading... message
// to newChatMessages, but we have to remove it later.
{
message: 'Loading...',
sender: 'robot',
id: crypto.randomUUID()
}
];

setChatMessages(newChatMessages);

const response = await Chatbot.getResponseAsync(inputText);
setChatMessages([
...newChatMessages,
// This makes a copy of newChatMessages, but without the
// last message in the array.
...newChatMessages.slice(0, newChatMessages.length - 1),
{
message: response,
sender: 'robot',
Expand Down

0 comments on commit eb84019

Please sign in to comment.