editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Allow block tool render() accept null without throwing error

Open jocelynRS opened this issue 3 years ago • 0 comments

I have a few custom Editor.js block tools that trigger a custom React component that opens a modal and allows the user to walk through a few steps and this component will then add the newly constructed block using blocks.insert(...).

Ideally I would like to be able to return null in my block tool render().

render() {
  ...
  return null;
}

But doing this throws a console error...

image

Currently only way to avoid this console error is for my block tool render() to return a node.

render() {
  ...
  return document.createElement('div');
}

But doing this adds an unnecessary block to the editor which in my application has other unintended consequences. I would like to avoid having to add a lot of extra unnecessary code to handle this additional/unneeded block.

image

I found one other previous issue (#768) where they also suggested making the appendChild void/null-proof. But looks like a different approach was used to solve that issue.

https://github.com/codex-team/editor.js/issues/768

another approach would be to accept render function returning void (or null) and make the appendChild void-proof (or null-proof)

Is there a way to achieve what I'm looking to do without updating the appendChild to be null-proof? If not, is this something that could be updated?

jocelynRS avatar Jul 06 '22 13:07 jocelynRS