Skip to content

Commit

Permalink
refactor: better usage of Virtuoso
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Apr 15, 2024
1 parent 099c165 commit e7e1049
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/webview/SearchSidebar/SearchResultList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useCallback } from 'react'
import { memo } from 'react'
import type { DisplayResult } from '../../../types'
import TreeItem from './TreeItem'
import { refScroller } from './useListState'
Expand All @@ -22,26 +22,19 @@ interface SearchResultListProps {
matches: Array<[string, DisplayResult[]]>
}

function itemContent(_: number, data: [string, DisplayResult[]]) {
return <TreeItem className={'sg-match-tree-item'} matches={data[1]} />
}
function computeItemKey(_: number, data: [string, DisplayResult[]]) {
return data[0]
}
const SearchResultList = ({ matches }: SearchResultListProps) => {
const render = useCallback(
(index: number) => {
const match = matches[index][1]
return <TreeItem className={'sg-match-tree-item'} matches={match} />
},
[matches],
)
const computeItemKey = useCallback(
(index: number) => {
return matches[index][0]
},
[matches],
)
return (
<Virtuoso
ref={refScroller}
{...stylex.props(styles.resultList)}
totalCount={matches.length}
itemContent={render}
data={matches}
itemContent={itemContent}
computeItemKey={computeItemKey}
/>
)
Expand Down

0 comments on commit e7e1049

Please sign in to comment.