From 43f0b935cf46ef5fe6b3488ac0c2b6185544115b Mon Sep 17 00:00:00 2001 From: oomeow Date: Sat, 18 May 2024 15:14:22 +0800 Subject: [PATCH] perf: memoize the proxy col items (#1029) --- src/components/proxy/proxy-groups.tsx | 2 +- src/components/proxy/proxy-render.tsx | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index 9d01d74..26e5ac0 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -122,7 +122,7 @@ export const ProxyGroups = (props: Props) => { return ( ( diff --git a/src/components/proxy/proxy-render.tsx b/src/components/proxy/proxy-render.tsx index b5423a2..8f8b927 100644 --- a/src/components/proxy/proxy-render.tsx +++ b/src/components/proxy/proxy-render.tsx @@ -19,7 +19,7 @@ import type { IRenderItem } from "./use-render-list"; import { useVerge } from "@/hooks/use-verge"; import { useRecoilState } from "recoil"; import { atomThemeMode } from "@/services/states"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { convertFileSrc } from "@tauri-apps/api/tauri"; import { downloadIconCache } from "@/services/cmds"; @@ -171,6 +171,18 @@ export const ProxyRender = (props: RenderProps) => { } if (type === 4 && !group.hidden) { + const proxyColItemsMemo = useMemo(() => { + return proxyCol?.map((proxy) => ( + onChangeProxy(group, proxy!)} + /> + )); + }, [proxyCol, group, headState]); return ( { gridTemplateColumns: `repeat(${item.col! || 2}, 1fr)`, }} > - {proxyCol?.map((proxy) => ( - onChangeProxy(group, proxy!)} - /> - ))} + {proxyColItemsMemo} ); }