@resourge/react-fetch
Version:
[](LICENSE)
32 lines (29 loc) • 1.11 kB
JavaScript
/**
* react-fetch v1.43.1
*
* Copyright (c) resourge.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
import { useBaseScrollRestoration } from '../useBaseScrollRestoration';
const visitedUrl = new Map();
const useInfiniteScrollRestoration = (action, scrollRestorationId = (_window => (_window = window) == null || (_window = _window.location) == null ? void 0 : _window.pathname)()) => {
const [scrollRestoration, ref, onScroll] = useBaseScrollRestoration(visitedUrl, action, scrollRestorationId);
scrollRestoration.getPage = () => {
return visitedUrl.get(scrollRestorationId);
};
scrollRestoration.setPage = (page, perPage) => {
const existingRecord = visitedUrl.get(scrollRestorationId);
visitedUrl.set(scrollRestorationId, {
pos: existingRecord == null ? void 0 : existingRecord.pos,
page,
perPage
});
};
return [scrollRestoration, ref, onScroll];
};
export { useInfiniteScrollRestoration };
//# sourceMappingURL=useInfiniteScrollRestoration.js.map