Tankōbon / hooks/use-resume-scroll / useResumeScroll
Function: useResumeScroll()
useResumeScroll(
scrollRef,columnRef,resumePage):RefObject<boolean>
Defined in: hooks/use-resume-scroll.ts:21
Scrolls the continuous reader to resumePage when a comic opens, and keeps that page pinned to the top while pages load: every page starts as a fixed-height placeholder, so pages above it (preloaded thanks to the observer's rootMargin) change height once their image arrives and would otherwise push the resumed page out of view. Pinning stops as soon as the user scrolls on their own.
Runs as a layout effect so the first scroll happens before the page observers' first (asynchronous) callbacks: page 0 is never reported as active, so the saved progress isn't overwritten with the start of the book.
Returns a ref that is true while the page is pinned, for whoever else adjusts the scroll position when a page changes height (the pinning already does it, and both together would shift twice).
Parameters
scrollRef
RefObject<HTMLDivElement | null>
columnRef
RefObject<HTMLDivElement | null>
resumePage
number
Returns
RefObject<boolean>