# useScrollToBlock

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



Returns a function that scrolls the viewport to a block, such as jumping to a search hit or a form field.

```ts
const scrollToBlock = useScrollToBlock()

scrollToBlock(blockId, options?)
```

* `blockId` is a block id from the SDK, such as a widget id from [useWidgets](https://sdk.pdf.net/docs/v1/reference/useWidgets). An unknown or deleted id throws `InvalidInputError`; with no document loaded, the call throws `DocumentNotLoadedError`.
* `options` are the same alignment options as in [useScrollToPage](https://sdk.pdf.net/docs/v1/reference/useScrollToPage), applied to the block's bounds instead of the page.

## Example [#example]

```tsx
import { useScrollToBlock, useWidgets } from '@sdk-pdf/react'

function useScrollToFirstEmptyField() {
  const { widgets } = useWidgets()
  const scrollToBlock = useScrollToBlock()

  return (fieldName: string) => {
    const widget = widgets.find((widget) => widget.fieldName === fieldName)
    if (widget) scrollToBlock(widget.id, { behavior: 'smooth', vertical: 'center' })
  }
}
```

