Creating a custom block tool in React #1885
Replies: 5 comments
-
That is because under the hood, the JSX This is a hacky way to make it work: render() {
// converts React element to HTML string
const html = ReactDOMServer.renderToString(<span>Hello world</span>);
// converts HTML string to HTML Document
const node = new DOMParser().parseFromString(html, "text/html");
// returns HTML element
return node.documentElement;
} Note I have not tested this code for more complicated use cases (e.g. nested components, stylings, complex logic). I suspect you'll need more hacky code along the way. It'd be nice if we could get official support for React with editor.js, but judging from #1202 it won't happen soon. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Sir that is very smart. I have not thought of that. |
Beta Was this translation helpful? Give feedback.
-
Inspired by @hata6502 's example, I extracted the logic and wrote a util function: https://gist.github.com/donfour/82193ab0c138afcc8c840c7a79474db4. Hope it's useful. |
Beta Was this translation helpful? Give feedback.
-
I have created a babel plugin that wraps a React component with block tool class definition. You can check it out here. Though, It is experimental, so use it at your own risk. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to return
React
markup when creating a custom block tool?I'm using Editor.js in React - The actual package without using
react-editor-js
.I'm trying to create a custom block element. It was possible to create the below block
and use it directly.
Is it possible to add React code in the render function here? For example like below:
When I tried this, it complained that the expected type is Node. Is there any way around this?
Beta Was this translation helpful? Give feedback.
All reactions