Skip to content

Commit 07c8667

Browse files
committed
feat(neuron-ui): memorize lists for performance
memorize the lists of transactions and addresses.
1 parent 7d2b5b8 commit 07c8667

2 files changed

Lines changed: 75 additions & 53 deletions

File tree

packages/neuron-ui/src/components/Addresses/index.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,24 @@ const Addresses = ({
158158
semanticColors,
159159
]
160160
)
161-
162-
return (
163-
<ShimmeredDetailsList
164-
enableShimmer={isLoading}
165-
checkboxVisibility={CheckboxVisibility.hidden}
166-
columns={addressColumns.map(col => ({ ...col, name: t(col.name) }))}
167-
items={addresses}
168-
onItemContextMenu={item => {
169-
contextMenu({ type: 'addressList', id: item.identifier })
170-
}}
171-
className="listWithDesc"
172-
onRenderRow={onRenderRow}
173-
/>
161+
const List = useMemo(
162+
() => (
163+
<ShimmeredDetailsList
164+
enableShimmer={isLoading}
165+
checkboxVisibility={CheckboxVisibility.hidden}
166+
columns={addressColumns.map(col => ({ ...col, name: t(col.name) }))}
167+
items={addresses}
168+
onItemContextMenu={item => {
169+
contextMenu({ type: 'addressList', id: item.identifier })
170+
}}
171+
className="listWithDesc"
172+
onRenderRow={onRenderRow}
173+
/>
174+
),
175+
[isLoading, addressColumns, addresses, t]
174176
)
177+
178+
return List
175179
}
176180

177181
Addresses.displayName = 'Addresses'

packages/neuron-ui/src/components/History/index.tsx

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect } from 'react'
1+
import React, { useCallback, useEffect, useMemo } from 'react'
22
import { RouteComponentProps } from 'react-router-dom'
33
import { useTranslation } from 'react-i18next'
44
import { Stack, SearchBox } from 'office-ui-fabric-react'
@@ -33,47 +33,65 @@ const History = ({
3333
}, [id, history])
3434
const onSearch = useCallback(() => history.push(`${Routes.History}?keywords=${keywords}`), [history, keywords])
3535

36-
return (
37-
<Stack>
38-
<Stack horizontal horizontalAlign="end" tokens={{ childrenGap: 15 }}>
39-
<SearchBox
40-
value={keywords}
41-
styles={{ root: { width: 500 } }}
42-
placeholder={t('history.search.placeholder')}
43-
onChange={onKeywordsChange}
44-
onSearch={onSearch}
45-
iconProps={{ iconName: 'Search', styles: { root: { height: '18px' } } }}
36+
const List = useMemo(() => {
37+
return (
38+
<Stack>
39+
<Stack horizontal horizontalAlign="end" tokens={{ childrenGap: 15 }}>
40+
<SearchBox
41+
value={keywords}
42+
styles={{ root: { width: 500 } }}
43+
placeholder={t('history.search.placeholder')}
44+
onChange={onKeywordsChange}
45+
onSearch={onSearch}
46+
iconProps={{ iconName: 'Search', styles: { root: { height: '18px' } } }}
47+
/>
48+
</Stack>
49+
<TransactionList
50+
isLoading={isLoading}
51+
isUpdatingDescription={isUpdatingDescription}
52+
walletID={id}
53+
items={items}
54+
dispatch={dispatch}
55+
/>
56+
<Pagination
57+
selectedPageIndex={pageNo - 1}
58+
pageCount={Math.ceil(totalCount / pageSize)}
59+
itemsPerPage={pageSize}
60+
totalItemCount={totalCount}
61+
previousPageAriaLabel={t('pagination.previous-page')}
62+
nextPageAriaLabel={t('pagination.next-page')}
63+
firstPageAriaLabel={t('pagination.first-page')}
64+
lastPageAriaLabel={t('pagination.last-page')}
65+
pageAriaLabel={t('pagination-page')}
66+
selectedAriaLabel={t('pagination-selected')}
67+
firstPageIconProps={{ iconName: 'FirstPage' }}
68+
previousPageIconProps={{ iconName: 'PrevPage' }}
69+
nextPageIconProps={{ iconName: 'NextPage' }}
70+
lastPageIconProps={{ iconName: 'LastPage' }}
71+
format="buttons"
72+
onPageChange={(idx: number) => {
73+
history.push(`${Routes.History}?pageNo=${idx + 1}`)
74+
}}
4675
/>
4776
</Stack>
48-
<TransactionList
49-
isLoading={isLoading}
50-
isUpdatingDescription={isUpdatingDescription}
51-
walletID={id}
52-
items={items}
53-
dispatch={dispatch}
54-
/>
55-
<Pagination
56-
selectedPageIndex={pageNo - 1}
57-
pageCount={Math.ceil(totalCount / pageSize)}
58-
itemsPerPage={pageSize}
59-
totalItemCount={totalCount}
60-
previousPageAriaLabel={t('pagination.previous-page')}
61-
nextPageAriaLabel={t('pagination.next-page')}
62-
firstPageAriaLabel={t('pagination.first-page')}
63-
lastPageAriaLabel={t('pagination.last-page')}
64-
pageAriaLabel={t('pagination-page')}
65-
selectedAriaLabel={t('pagination-selected')}
66-
firstPageIconProps={{ iconName: 'FirstPage' }}
67-
previousPageIconProps={{ iconName: 'PrevPage' }}
68-
nextPageIconProps={{ iconName: 'NextPage' }}
69-
lastPageIconProps={{ iconName: 'LastPage' }}
70-
format="buttons"
71-
onPageChange={(idx: number) => {
72-
history.push(`${Routes.History}?pageNo=${idx + 1}`)
73-
}}
74-
/>
75-
</Stack>
76-
)
77+
)
78+
}, [
79+
keywords,
80+
onKeywordsChange,
81+
onSearch,
82+
isLoading,
83+
isUpdatingDescription,
84+
id,
85+
items,
86+
dispatch,
87+
pageNo,
88+
totalCount,
89+
pageSize,
90+
history,
91+
t,
92+
])
93+
94+
return List
7795
}
7896

7997
History.displayName = 'History'

0 commit comments

Comments
 (0)