From 07c8667e4cad89c7eafcfa59a5aa2fc826ca286a Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 15 Aug 2019 00:31:26 +0800 Subject: [PATCH] feat(neuron-ui): memorize lists for performance memorize the lists of transactions and addresses. --- .../src/components/Addresses/index.tsx | 30 +++--- .../src/components/History/index.tsx | 98 +++++++++++-------- 2 files changed, 75 insertions(+), 53 deletions(-) diff --git a/packages/neuron-ui/src/components/Addresses/index.tsx b/packages/neuron-ui/src/components/Addresses/index.tsx index 480e95c114..7d51198ac4 100644 --- a/packages/neuron-ui/src/components/Addresses/index.tsx +++ b/packages/neuron-ui/src/components/Addresses/index.tsx @@ -158,20 +158,24 @@ const Addresses = ({ semanticColors, ] ) - - return ( - ({ ...col, name: t(col.name) }))} - items={addresses} - onItemContextMenu={item => { - contextMenu({ type: 'addressList', id: item.identifier }) - }} - className="listWithDesc" - onRenderRow={onRenderRow} - /> + const List = useMemo( + () => ( + ({ ...col, name: t(col.name) }))} + items={addresses} + onItemContextMenu={item => { + contextMenu({ type: 'addressList', id: item.identifier }) + }} + className="listWithDesc" + onRenderRow={onRenderRow} + /> + ), + [isLoading, addressColumns, addresses, t] ) + + return List } Addresses.displayName = 'Addresses' diff --git a/packages/neuron-ui/src/components/History/index.tsx b/packages/neuron-ui/src/components/History/index.tsx index a47fa6266a..d6b0250847 100644 --- a/packages/neuron-ui/src/components/History/index.tsx +++ b/packages/neuron-ui/src/components/History/index.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect } from 'react' +import React, { useCallback, useEffect, useMemo } from 'react' import { RouteComponentProps } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { Stack, SearchBox } from 'office-ui-fabric-react' @@ -33,47 +33,65 @@ const History = ({ }, [id, history]) const onSearch = useCallback(() => history.push(`${Routes.History}?keywords=${keywords}`), [history, keywords]) - return ( - - - { + return ( + + + + + + { + history.push(`${Routes.History}?pageNo=${idx + 1}`) + }} /> - - { - history.push(`${Routes.History}?pageNo=${idx + 1}`) - }} - /> - - ) + ) + }, [ + keywords, + onKeywordsChange, + onSearch, + isLoading, + isUpdatingDescription, + id, + items, + dispatch, + pageNo, + totalCount, + pageSize, + history, + t, + ]) + + return List } History.displayName = 'History'