From 49c66f7a10ad08e3a3c25f9b029aeca7bffbf4ab Mon Sep 17 00:00:00 2001 From: WofWca Date: Wed, 25 Dec 2024 16:06:45 +0400 Subject: [PATCH] perf: add useMemo for `contactsAndExtraItems` --- .../components/dialogs/CreateChat/index.tsx | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/components/dialogs/CreateChat/index.tsx b/packages/frontend/src/components/dialogs/CreateChat/index.tsx index adcb620e0..3249e3d0b 100644 --- a/packages/frontend/src/components/dialogs/CreateChat/index.tsx +++ b/packages/frontend/src/components/dialogs/CreateChat/index.tsx @@ -169,15 +169,30 @@ function CreateChatMain(props: CreateChatMainProps) { ADD_BROADCAST_LIST, ADD_CONTACT, } - const contactsAndExtraItems = [ - ...(needToRenderAddContactQRScan - ? [ExtraItemType.ADD_CONTACT_QR_SCAN] - : []), - ...(needToRenderAddGroup ? [ExtraItemType.ADD_GROUP] : []), - ...(needToRenderAddBroadcastList ? [ExtraItemType.ADD_BROADCAST_LIST] : []), - ...contactIds, - ...(needToRenderAddContact ? [ExtraItemType.ADD_CONTACT] : []), - ] + const contactsAndExtraItems = useMemo( + () => [ + ...(needToRenderAddContactQRScan + ? [ExtraItemType.ADD_CONTACT_QR_SCAN] + : []), + ...(needToRenderAddGroup ? [ExtraItemType.ADD_GROUP] : []), + ...(needToRenderAddBroadcastList + ? [ExtraItemType.ADD_BROADCAST_LIST] + : []), + ...contactIds, + ...(needToRenderAddContact ? [ExtraItemType.ADD_CONTACT] : []), + ], + [ + ExtraItemType.ADD_BROADCAST_LIST, + ExtraItemType.ADD_CONTACT, + ExtraItemType.ADD_CONTACT_QR_SCAN, + ExtraItemType.ADD_GROUP, + contactIds, + needToRenderAddBroadcastList, + needToRenderAddContact, + needToRenderAddContactQRScan, + needToRenderAddGroup, + ] + ) const openQRScan = async () => { const [qrCode, qrCodeSVG] =