From eb84019dc55f18412d7d8fac9b2f5f279cd50a0e Mon Sep 17 00:00:00 2001 From: SuperSimpleDev Date: Thu, 31 Oct 2024 17:41:32 -0400 Subject: [PATCH] 3l Solution 2 --- 2-copy-of-code/lesson-03/chatbot.html | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/2-copy-of-code/lesson-03/chatbot.html b/2-copy-of-code/lesson-03/chatbot.html index 054b112..38bc7d9 100755 --- a/2-copy-of-code/lesson-03/chatbot.html +++ b/2-copy-of-code/lesson-03/chatbot.html @@ -27,6 +27,13 @@ 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() } ]; @@ -34,7 +41,9 @@ 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',