UNPKG

@resourge/react-fetch

Version:

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

32 lines (29 loc) 1.11 kB
/** * react-fetch v1.41.3 * * 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