useBlockPageIdGetter

Returns a getter that resolves a block id to the id of the page holding the block, without subscribing the component to changes.

const getBlockPageId = useBlockPageIdGetter()

const pageId = getBlockPageId(blockId) // string | undefined

The getter returns undefined when the block is deleted or unknown: an id can go stale, so handle that case.

Example

import { useBlockPageIdGetter, useScrollToPage } from '@sdk-pdf/react'

function useScrollToBlockPage() {
  const getBlockPageId = useBlockPageIdGetter()
  const scrollToPage = useScrollToPage()

  return (blockId: string) => {
    const pageId = getBlockPageId(blockId)
    if (pageId) scrollToPage(pageId)
  }
}

On this page