codex-team / codex-team/editor.js

Allow block tool render() accept null without throwing error

Open
#2,092 0 comments 7 reactions 0 assignees View on GitHub
nice to have
Dominant language
TypeScript
Stars
31.9k
Forks
2.2k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

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](https://user-images.githubusercontent.com/58474278/177558853-dd0ff809-f1fd-4268-86be-01d3f6b90e29.png)

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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.