Shows a feed as it was left when the user comes back to it, instead of fetching it again. It keeps the feed's loaded pages and scroll position in sessionStorage.
Returns the feed saved under key and a way to save it. The feed pages and
useUserDumpFeed use it. key must tell apart every list whose items
differ; the viewer is added to it here, since they see their own private
items. hydrateItem restores what JSON lost, such as dates. A full or
blocked storage is ignored.
Stored as JSON by useFeedCache's saveState, and read back by the
hook when the page is next reached by going back.
- hasMore: boolean
-
items: T[]
It holds every page loaded so far, whose dates JSON turns into strings.
-
page: number
Loading more carries on from this page, the last loaded.
-
savedAt: number
In epoch milliseconds.
- scrollY: number
Returned by useFeedCache to a feed page.
-
cached: Omit<FeedCacheEntry<T>, "savedAt"> | null
It holds the saved feed when the page was reached by going back or forward and the feed was saved less than 10 minutes ago. It changes only with the key.
-
saveState: () => voidlist: SavedList<T>,scrollY: number
Usually called through
useScrollSave, as the page is left.
Passed to useFeedCache's saveState by the feed pages, from the
list they hold, without its loading flag.
Usage
import * as mod from "src/hooks/feed/useFeedCache.ts";