# usePageIndexGetter

Source: https://sdk.pdf.net/docs/v1/reference/usePageIndexGetter



Returns a getter that resolves a page id to its index in the document, without subscribing the component to page order changes.

```ts
const getPageIndex = usePageIndexGetter()

const pageIndex = getPageIndex(pageId) // number | undefined
```

* The getter returns `undefined` when the page is deleted or unknown: an id can go stale, so handle that case.
* Use it where the index is needed occasionally, such as inside an event handler. When the resolved index is rendered, pair it with [useRenderOnPageOrderChange](https://sdk.pdf.net/docs/v1/reference/useRenderOnPageOrderChange) so the component re-renders when the order changes; for a rendered, always-fresh list, prefer [usePages](https://sdk.pdf.net/docs/v1/reference/usePages).

## Example [#example]

```tsx
import { usePageIndexGetter } from '@sdk-pdf/react'

function useCopyPageLink() {
  const getPageIndex = usePageIndexGetter()

  return (pageId: string) => {
    const pageIndex = getPageIndex(pageId)
    if (pageIndex === undefined) return

    void navigator.clipboard.writeText(
      `${location.origin}${location.pathname}#page=${pageIndex + 1}`
    )
  }
}
```

