mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-21 05:00:16 +09:00
Fix [UI/UX] [Chat] [Front End] React Warning
- [+] refactor(chat.tsx): capture current input reference value for use in component unmount or dependencies change
This commit is contained in:
parent
67ce78cac2
commit
e05af75891
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user