From d0103d8fef6210851dbd2c9a9a045f5024a51d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9F=E8=B4=A4?= Date: Mon, 15 Jan 2024 18:49:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20unuse=20useMemo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ChatList/Item.tsx | 59 ++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/ChatList/Item.tsx b/src/ChatList/Item.tsx index fc0d475b..208f9371 100644 --- a/src/ChatList/Item.tsx +++ b/src/ChatList/Item.tsx @@ -1,6 +1,6 @@ import { App } from 'antd'; import copy from 'copy-to-clipboard'; -import { FC, ReactNode, useCallback, useMemo, useState } from 'react'; +import { FC, ReactNode, useMemo, useState } from 'react'; import { ActionEvent } from '@/ActionIconGroup'; import ChatItem, { type ChatItemProps } from '@/ChatItem'; @@ -141,39 +141,36 @@ const Item = (props: ChatListItemProps) => { return ; }); - const Actions = useCallback( - ({ data }: { data: ChatMessage }) => { - if (!renderActions || !item?.role) return; - let RenderFunction; - if (renderActions?.[item.role]) RenderFunction = renderActions[item.role]; - if (renderActions?.['default']) RenderFunction = renderActions['default']; - if (!RenderFunction) RenderFunction = ActionsBar; - - const handleActionClick: ListItemProps['onActionsClick'] = (action, data) => { - switch (action.key) { - case 'copy': { - copy(data.content as string); - message.success(text?.copySuccess || 'Copy Success'); - break; - } - case 'edit': { - setEditing(true); - } + const Actions = useRefFunction(({ data }: { data: ChatMessage }) => { + if (!renderActions || !item?.role) return; + let RenderFunction; + if (renderActions?.[item.role]) RenderFunction = renderActions[item.role]; + if (renderActions?.['default']) RenderFunction = renderActions['default']; + if (!RenderFunction) RenderFunction = ActionsBar; + + const handleActionClick: ListItemProps['onActionsClick'] = (action, data) => { + switch (action.key) { + case 'copy': { + copy(data.content as string); + message.success(text?.copySuccess || 'Copy Success'); + break; + } + case 'edit': { + setEditing(true); } + } - onActionsClick?.(action, data); - }; + onActionsClick?.(action, data); + }; - return ( - handleActionClick?.(actionKey, data)} - text={text} - /> - ); - }, - [renderActions?.[item.role], text, onActionsClick], - ); + return ( + handleActionClick?.(actionKey, data)} + text={text} + /> + ); + }); const error = useMemo(() => { if (!item.error) return;