useSelectBlocks

Returns a function that replaces the current selection with the given blocks, such as for a "select all fields" action or selecting a block from a list.

const selectBlocks = useSelectBlocks()

selectBlocks(blockIds)
selectBlocks([]) // Unselects everything.
  • Every id must identify an existing block, or the call throws InvalidInputError and the selection stays unchanged; with no document loaded, it throws DocumentNotLoadedError.
  • The blocks become selected in the main view exactly as if the user selected them.
  • To read the selection, see useSelection for the selected ids or useSelectedBlocks for their content.

Example

import { useSelectBlocks, useWidgets } from '@sdk-pdf/react'

function SelectAllFieldsButton() {
  const { widgets } = useWidgets()
  const selectBlocks = useSelectBlocks()

  return (
    <button onClick={() => selectBlocks(widgets.map((widget) => widget.id))}>
      Select all fields
    </button>
  )
}

On this page