import React, { useCallback, useState } from 'react'; import { WindowScroller, AutoSizer, List, InfiniteLoader } from 'react-virtualized'; import _ from 'lodash'; import { Poll } from 'which-types'; import RenderItem from './RenderItem'; interface PropTypes { polls: Poll[]; mutate: (polls: Poll[], refetch: boolean) => void; } const PAGE_SIZE = 10; const PollsList: React.FC = ({ polls, mutate }) => { const [displayCount, setDisplayCount] = useState(PAGE_SIZE); const rowRenderer = useCallback(({ index, style, key }) => ( ), [polls, mutate]); const loadMoreRows = useCallback(async () => { setDisplayCount(previousCount => { return _.min([polls.length, previousCount + PAGE_SIZE]) || polls.length; }); }, [polls]); const isRowLoaded = useCallback(({ index }) => { return index < displayCount - 1 || displayCount === polls.length; }, [displayCount, polls]); return ( {({ height, isScrolling, registerChild, onChildScroll, scrollTop }) => ( {({ width }) => (
{({ onRowsRendered, registerChild: ref }) => ( )}
)}
)}
); }; export default PollsList;