From e05af7589159ebb569fe76933e911eca53f5878c Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 5 Feb 2024 20:40:22 +0700 Subject: [PATCH] Fix [UI/UX] [Chat] [Front End] React Warning - [+] refactor(chat.tsx): capture current input reference value for use in component unmount or dependencies change --- app/components/chat.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 1c2ef9bec..5fe350a0b 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1044,10 +1044,14 @@ function _Chat() { localStorage.removeItem(key); } - // This function will be called when the component unmounts. + // Capture the current value of the input reference. + const currentInputRef = inputRef.current; + + // This function will be called when the component unmounts or dependencies change. return () => { // Save the current input to local storage only if it is not a command. - const currentInputValue = inputRef.current?.value ?? ""; + // Use the captured value from the input reference. + const currentInputValue = currentInputRef?.value ?? ""; if (!currentInputValue.startsWith(ChatCommandPrefix)) { localStorage.setItem(key, currentInputValue); }