Skip to content

Commit

Permalink
Fix [UI/UX] [Chat] [Front End] React Warning
Browse files Browse the repository at this point in the history
- [+] refactor(chat.tsx): capture current input reference value for use in component unmount or dependencies change
  • Loading branch information
H0llyW00dzZ committed Feb 5, 2024
1 parent 67ce78c commit e05af75
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e05af75

Please sign in to comment.