Skip to content

onDelete, onRemove or onRemoveBlocks event handler #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
coxato opened this issue Mar 26, 2025 · 2 comments
Open

onDelete, onRemove or onRemoveBlocks event handler #1566

coxato opened this issue Mar 26, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@coxato
Copy link

coxato commented Mar 26, 2025

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?

@coxato coxato added the enhancement New feature or request label Mar 26, 2025
@nperez0111
Copy link
Contributor

This is related to an issue we are tracking: #1566

@coxato
Copy link
Author

coxato commented Mar 26, 2025

This is related to an issue we are tracking: #1566

oh, very nice. I will keep an eye out for any news.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants