Cache all props in ListView
This commit is contained in:
parent
fdaaa531b3
commit
4326e38112
1 changed files with 16 additions and 7 deletions
|
@ -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}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue