UNPKG

3.34 kBTypeScriptView Raw
1import type * as PropTypes from "prop-types";
2import { PureComponent } from "react";
3import { Index, IndexRange } from "../../index";
4
5export type InfiniteLoaderChildProps = {
6 onRowsRendered: (params: IndexRange) => void;
7 registerChild: (registeredChild: any) => void;
8};
9
10export type InfiniteLoaderProps = {
11 /**
12 * Function responsible for rendering a virtualized component.
13 * This function should implement the following signature:
14 * ({ onRowsRendered, registerChild }) => PropTypes.element
15 *
16 * The specified :onRowsRendered function should be passed through to the child's :onRowsRendered property.
17 * The :registerChild callback should be set as the virtualized component's :ref.
18 */
19 children: (props: InfiniteLoaderChildProps) => React.ReactNode;
20 /**
21 * Function responsible for tracking the loaded state of each row.
22 * It should implement the following signature: ({ index: number }): boolean
23 */
24 isRowLoaded: (params: Index) => boolean;
25 /**
26 * Callback to be invoked when more rows must be loaded.
27 * It should implement the following signature: ({ startIndex, stopIndex }): Promise
28 * The returned Promise should be resolved once row data has finished loading.
29 * It will be used to determine when to refresh the list with the newly-loaded data.
30 * This callback may be called multiple times in reaction to a single scroll event.
31 */
32 loadMoreRows: (params: IndexRange) => Promise<any>;
33 /**
34 * Minimum number of rows to be loaded at a time.
35 * This property can be used to batch requests to reduce HTTP requests.
36 */
37 minimumBatchSize?: number | undefined;
38 /**
39 * Number of rows in list; can be arbitrary high number if actual number is unknown.
40 */
41 rowCount?: number | undefined;
42 /**
43 * Threshold at which to pre-fetch data.
44 * A threshold X means that data will start loading when a user scrolls within X rows.
45 * This value defaults to 15.
46 */
47 threshold?: number | undefined;
48 /**
49 * PLEASE NOTE
50 * The [key: string]: any; line is here on purpose
51 * This is due to the need of force re-render of PureComponent
52 * Check the following link if you want to know more
53 * https://github.com/bvaughn/react-virtualized#pass-thru-props
54 */
55 [key: string]: any;
56};
57
58/**
59 * Higher-order component that manages lazy-loading for "infinite" data.
60 * This component decorates a virtual component and just-in-time prefetches rows as a user scrolls.
61 * It is intended as a convenience component; fork it if you'd like finer-grained control over data-loading.
62 */
63export class InfiniteLoader extends PureComponent<InfiniteLoaderProps> {
64 static propTypes: {
65 children: PropTypes.Validator<(props: InfiniteLoaderChildProps) => React.ReactNode>;
66 isRowLoaded: PropTypes.Validator<(params: Index) => boolean>;
67 loadMoreRows: PropTypes.Validator<(params: IndexRange) => Promise<any>>;
68 minimumBatchSize: PropTypes.Validator<number>;
69 rowCount: PropTypes.Validator<number>;
70 threshold: PropTypes.Validator<number>;
71 };
72
73 static defaultProps: {
74 minimumBatchSize: 10;
75 rowCount: 0;
76 threshold: 15;
77 };
78
79 resetLoadMoreRowsCache(autoReload?: boolean): void;
80}
81
82export default InfiniteLoader;