useWidgetsGetter
Returns an asynchronous callback that resolves with all document widgets in reading order, for imperative whole-form operations: exporting values, bulk edits, lookups inside event handlers.
const getWidgets = useWidgetsGetter()
const widgets = await getWidgets()- The callback loads every page containing widgets before resolving, so the result is always complete; that load can take a while on a large document the first time.
- The entries are the same
Widgetsnapshots as in useWidgets. PreferuseWidgetswhen the widgets are rendered: it re-renders on changes, while the getter is a one-time read. - With no document loaded, the callback resolves with an empty array.
Example
import { useBlockDelete, useWidgetsGetter } from '@sdk-pdf/react'
function useDeleteWidgetsByFieldName() {
const getWidgets = useWidgetsGetter()
const deleteBlocks = useBlockDelete()
return async (fieldName: string) => {
const widgets = await getWidgets()
deleteBlocks(
widgets
.filter((widget) => widget.fieldName === fieldName)
.map((widget) => widget.id)
)
}
}