Skip to content

Commit 86426e5

Browse files
Use useInfiniteLoader hook instead of InfiniteLoader component
Replace InfiniteLoader component with the useInfiniteLoader hook as suggested by @dennisoelkers. The hook provides a cleaner API and better type safety. This eliminates the render prop pattern in favor of a direct hook call. Co-authored-by: dennisoelkers <41929+dennisoelkers@users.noreply.github.com>
1 parent ccbdcab commit 86426e5

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

graylog2-web-interface/src/components/common/Select/AsyncCustomMenuList.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import * as React from 'react';
1818
import { useRef } from 'react';
19-
import { InfiniteLoader } from 'react-window-infinite-loader';
19+
import { useInfiniteLoader } from 'react-window-infinite-loader';
2020
import styled from 'styled-components';
2121

2222
import { WindowList } from 'components/common/Select/CustomMenuList';
@@ -45,19 +45,18 @@ const AsyncCustomMenuList = ({
4545
const items = children?.length ? children : [getNoOptionMessage()];
4646
const listRef = useRef(null);
4747

48+
const onRowsRendered = useInfiniteLoader({
49+
isRowLoaded: (index: number) => index < children.length,
50+
rowCount: total,
51+
threshold: 30,
52+
minimumBatchSize: 50,
53+
loadMoreRows: loadOptions,
54+
});
55+
4856
return (
49-
<InfiniteLoader
50-
isRowLoaded={(index: number) => index < children.length}
51-
rowCount={total}
52-
threshold={30}
53-
minimumBatchSize={50}
54-
loadMoreRows={loadOptions}>
55-
{({ onRowsRendered }) => (
56-
<WindowList listRef={listRef} onRowsRendered={onRowsRendered}>
57-
{items}
58-
</WindowList>
59-
)}
60-
</InfiniteLoader>
57+
<WindowList listRef={listRef} onRowsRendered={onRowsRendered}>
58+
{items}
59+
</WindowList>
6160
);
6261
};
6362

0 commit comments

Comments
 (0)