From 3b17ca791bcd4864117f817f37b38ae7643f0ace Mon Sep 17 00:00:00 2001 From: ecwu Date: Sun, 26 Jan 2025 21:39:23 +0000 Subject: [PATCH] feat: optimize LongInput component with memoization and local state management --- src/components/Settings.tsx | 105 ++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 40 deletions(-) diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index 4a283ad..6f4c40c 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -1,7 +1,8 @@ import { themeChange } from "theme-change"; -import { useRef } from "react"; +import { useRef, useCallback } from "react"; import { useContext, useEffect, useState, Dispatch } from "react"; +import React from "react"; import { clearTotalCost, getTotalCost } from "@/utils/totalCost"; import { ChatStore, TemplateChatStore, TemplateTools } from "@/types/chatstore"; import { models } from "@/types/models"; @@ -179,46 +180,70 @@ const SelectModel = (props: { help: string }) => { ); }; -const LongInput = (props: { - field: "systemMessageContent" | "toolsString"; - label: string; - help: string; -}) => { - const { chatStore, setChatStore } = useContext(AppChatStoreContext); - return ( -
- +const LongInput = React.memo( + (props: { + field: "systemMessageContent" | "toolsString"; + label: string; + help: string; + }) => { + const { chatStore, setChatStore } = useContext(AppChatStoreContext); + const textareaRef = useRef(null); + const [localValue, setLocalValue] = useState(chatStore[props.field]); -