useScrollToPage
Returns a function that scrolls the viewport to a page.
const scrollToPage = useScrollToPage()
scrollToPage(pageId, options?)pageIdis an id obtained from usePages. An unknown or deleted id throwsInvalidInputError; with no document loaded, the call throwsDocumentNotLoadedError.optionscontrols where the page lands in the viewport:
| Option | Values | Default | What it does |
|---|---|---|---|
behavior | 'auto' | 'smooth' | 'instant' | 'auto' | The scroll animation, as in native scrolling. |
vertical | 'top' | 'center' | 'bottom' | 'nearest' | 'top' | Which vertical viewport edge the page aligns to. |
horizontal | 'left' | 'center' | 'right' | 'nearest' | 'nearest' | Which horizontal viewport edge the page aligns to. |
The edges are physical: they don't change with the writing mode or text direction.
Example
const scrollToPage = useScrollToPage()
scrollToPage(page.id, { behavior: 'smooth', vertical: 'center' })