Skip to content

Commit e7e1049

Browse files
refactor: better usage of Virtuoso
1 parent 099c165 commit e7e1049

File tree

1 file changed

+9
-16
lines changed
  • src/webview/SearchSidebar/SearchResultList

1 file changed

+9
-16
lines changed

src/webview/SearchSidebar/SearchResultList/index.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback } from 'react'
1+
import { memo } from 'react'
22
import type { DisplayResult } from '../../../types'
33
import TreeItem from './TreeItem'
44
import { refScroller } from './useListState'
@@ -22,26 +22,19 @@ interface SearchResultListProps {
2222
matches: Array<[string, DisplayResult[]]>
2323
}
2424

25+
function itemContent(_: number, data: [string, DisplayResult[]]) {
26+
return <TreeItem className={'sg-match-tree-item'} matches={data[1]} />
27+
}
28+
function computeItemKey(_: number, data: [string, DisplayResult[]]) {
29+
return data[0]
30+
}
2531
const SearchResultList = ({ matches }: SearchResultListProps) => {
26-
const render = useCallback(
27-
(index: number) => {
28-
const match = matches[index][1]
29-
return <TreeItem className={'sg-match-tree-item'} matches={match} />
30-
},
31-
[matches],
32-
)
33-
const computeItemKey = useCallback(
34-
(index: number) => {
35-
return matches[index][0]
36-
},
37-
[matches],
38-
)
3932
return (
4033
<Virtuoso
4134
ref={refScroller}
4235
{...stylex.props(styles.resultList)}
43-
totalCount={matches.length}
44-
itemContent={render}
36+
data={matches}
37+
itemContent={itemContent}
4538
computeItemKey={computeItemKey}
4639
/>
4740
)

0 commit comments

Comments
 (0)