1.0.0-beta.17 • Published 2 years ago
use-buffered-pagination v1.0.0-beta.17
use-buffered-pagination
React hook to achieve memory-efficient buffered pagination
Showcase
function Component() {
const [searchQuery, setSearchQuery] = useState("");
const pagination = useBufferedPagination<number>({
query: searchQuery, // a buffer will be created for every different query
count: undefined, // if not set, will be calculated after fetching
page: 0, // the initial page for the current query
pageSize: 0, // the initial page size
pageBufferRadius: 1, // the radius of the buffer
queryBackstackSize: 1, // how many query buffers can be retain at once
async fetch(params) {
// the first (default) range to fetch
params.range;
// the first range with padding
params.paddedRange;
// the currently known items count
params.count;
// negative if the user is paginating backwards
// and positive when paginating forwards
params.direction;
// the list of all the ranges to be fetch (if possible)
params.ranges;
const [dataOffset, data] = myFetchFunction(params);
return {
remaining, // the remaining items, can be omitted or be a negative value
slices: [
new BufferSlice(dataOffset, data)
// it is allowed to pass more than one slice
// the slices will be joind and arranged
// depending on the offset of each slice
]
};
}
});
// page control
pagination.page;
pagination.setPage;
pagination.pageSize;
pagination.setPageSize;
// data
pagination.count;
pagination.pageCount;
pagination.loading;
pagination.sequential; // if all the items is available
pagination.absence; // the absent ranges in the data
pagination.data;
pagination.fetch(/* ... */); // force the hook to fetch some range
pagination.insert(/* ... */); // insert data directly to the hook
return <></>;
}
1.0.0-beta.17
2 years ago
1.0.0-beta.16
2 years ago
1.0.0-beta.15
2 years ago
1.0.0-beta.14
2 years ago
1.0.0-beta.13
2 years ago
1.0.0-beta.12
2 years ago
1.0.0-beta.11
2 years ago
1.0.0-beta.10
2 years ago
1.0.0-beta.9
2 years ago
1.0.0-beta.8
2 years ago
1.0.0-beta.7
2 years ago
1.0.0-beta.6
2 years ago
1.0.0-beta.5
2 years ago
1.0.0-beta.4
2 years ago
1.0.0-beta.3
2 years ago
1.0.0-beta.2
2 years ago
1.0.0-beta.1
2 years ago
1.0.0-beta.0
2 years ago