Skip to content

onDelete, onRemove or onRemoveBlocks event handler #1566

Closed
@coxato

Description

@coxato

Is your feature request related to a problem? Please describe.
I would like to have a specific event handler when a block or blocks are deleted, because I have some linked blocks that are being added as pairs, e.g (startBlock and endBlock) so if I delete a startBlock the endBlock is automatically deleted, because they are "pairs" in my implementation.
So I don't want to do that validation on the onChange method every time.

Describe the solution you'd like
Having a onDelete or onRemove or onContentDeleted or onRemoveBlocks event, so it receives a callback with the deleted blocks[] as argument.
something like this:

  const editor = useCreateBlockNote();

  useEffect(() => {
    if(editor){
      // a function to know when blocks are deleted so we don't use onChange every time  
      editor.onRemoveBlocks((deletedBlocksArray) => {
        myCustomHandler(deletedBlocksArray);
      })
    }
  }, [editor]);

Describe alternatives you've considered
Right now I do a validation for ALL the blocks on every onChange, but I think isn't the best approach, I would like to do those validations only when a block is deleted, if we are editing or creating/adding blocks I don't need to do extra validations.

is there any other possible solution?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions