import { PureComponent, Validator, Requireable } from 'react' import { Index, IndexRange } from './genericTypes'; export type InfiniteLoaderChildProps = { onRowsRendered: (params: { startIndex: number, stopIndex: number }) => void, registerChild: (registeredChild: any) => void } export type InfiniteLoaderProps = { children?: (props: InfiniteLoaderChildProps) => React.ReactNode; isRowLoaded: (params: Index) => boolean; loadMoreRows: (params: IndexRange) => Promise; minimumBatchSize?: number; rowCount?: number; threshold?: number; }; /** * Higher-order component that manages lazy-loading for "infinite" data. * This component decorates a virtual component and just-in-time prefetches rows as a user scrolls. * It is intended as a convenience component; fork it if you'd like finer-grained control over data-loading. */ export class InfiniteLoader extends PureComponent { static propTypes: { /** * Function responsible for rendering a virtualized component. * This function should implement the following signature: * ({ onRowsRendered, registerChild }) => PropTypes.element * * The specified :onRowsRendered function should be passed through to the child's :onRowsRendered property. * The :registerChild callback should be set as the virtualized component's :ref. */ children: Validator<(props: InfiniteLoaderChildProps) => React.ReactNode>, /** * Function responsible for tracking the loaded state of each row. * It should implement the following signature: ({ index: number }): boolean */ isRowLoaded: Validator<(params: Index) => boolean>, /** * Callback to be invoked when more rows must be loaded. * It should implement the following signature: ({ startIndex, stopIndex }): Promise * The returned Promise should be resolved once row data has finished loading. * It will be used to determine when to refresh the list with the newly-loaded data. * This callback may be called multiple times in reaction to a single scroll event. */ loadMoreRows: Validator<(params: IndexRange) => Promise>, /** * Minimum number of rows to be loaded at a time. * This property can be used to batch requests to reduce HTTP requests. */ minimumBatchSize: Validator, /** * Number of rows in list; can be arbitrary high number if actual number is unknown. */ rowCount: Validator, /** * Threshold at which to pre-fetch data. * A threshold X means that data will start loading when a user scrolls within X rows. * This value defaults to 15. */ threshold: Validator }; static defaultProps: { minimumBatchSize: 10, rowCount: 0, threshold: 15 }; constructor(props: InfiniteLoaderProps, context: any); resetLoadMoreRowsCache(): void; render(): JSX.Element; }