Cache all props in ListView

This commit is contained in:
Fedor Indutny 2023-01-03 16:53:22 -08:00 committed by GitHub
parent fdaaa531b3
commit 4326e38112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import classNames from 'classnames'; import classNames from 'classnames';
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef, useCallback, useMemo } from 'react';
import type { Index, ListRowRenderer } from 'react-virtualized'; import type { Index, ListRowRenderer } from 'react-virtualized';
import { List } from 'react-virtualized'; import { List } from 'react-virtualized';
import { ScrollBehavior } from '../types/Util'; import { ScrollBehavior } from '../types/Util';
@ -45,6 +45,19 @@ export function ListView({
} }
}); });
const rowHeight = useCallback(
(index: Index) => calculateRowHeight(index.index),
[calculateRowHeight]
);
const style = useMemo(() => {
return {
// See `<Timeline>` for an explanation of this `any` cast.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
overflowY: scrollable ? ('overlay' as any) : 'hidden',
};
}, [scrollable]);
return ( return (
<List <List
className={classNames( className={classNames(
@ -56,14 +69,10 @@ export function ListView({
height={height} height={height}
ref={listRef} ref={listRef}
rowCount={rowCount} rowCount={rowCount}
rowHeight={(index: Index) => calculateRowHeight(index.index)} rowHeight={rowHeight}
rowRenderer={rowRenderer} rowRenderer={rowRenderer}
scrollToIndex={scrollToIndex} scrollToIndex={scrollToIndex}
style={{ style={style}
// See `<Timeline>` for an explanation of this `any` cast.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
overflowY: scrollable ? ('overlay' as any) : 'hidden',
}}
tabIndex={-1} tabIndex={-1}
/> />
); );