useBlockDelete

Returns a function that deletes blocks of any kind (paragraphs, widgets, and other annotations) by id, one or several at once as a single undo step.

const deleteBlocks = useBlockDelete()

deleteBlocks(blockIds)
  • Every id must identify an existing block, or the call throws InvalidInputError and deletes nothing; with no document loaded, it throws DocumentNotLoadedError.
  • A deleted block is not necessarily gone forever: an undo can restore it.
  • Deleting a widget doesn't erase its stored field value (see Working with forms).

To delete whatever the user selected instead of specific ids, see useDeleteSelection.