Creating a custom block tool in React
See original GitHub issueIs 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
export default class SampleBlock {
static get toolbox() {
return {
title: 'SampleBlock',
icon:
'<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>',
};
}
render() {
return document.createElement('span');
}
save(blockContent) {
return {
url: blockContent.value,
};
}
}
and use it directly.
Is it possible to add React code in the render function here? For example like below:
export default class SampleBlock {
static get toolbox() {
return {
title: 'SampleBlock',
icon:
'<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>',
};
}
render() {
return (
<span>Hello world</span>
)
}
save(blockContent) {
return {
url: blockContent.value,
};
}
}
When I tried this, it complained that the expected type is Node. Is there any way around this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Creating a custom editorjs block tool with React
In this codelab, we walk you through to create a new custom block tool that shows nice timeline in the editorjs.
Read more >Creating a Block Tool - Editor.js
In this series of articles, we will learn how to create a full-featured Block Tool step-by-step. We will consider all methods and abilities...
Read more >Creating Custom Gutenberg Blocks with React and WordPress
In this post I'll explain how and why you should use Gulp to improve your workflow when building custom Gutenberg blocks with React...
Read more >editorjs-react-editor-js-example-with-custom ... - CodeSandbox
This Sandbox is in sync with master on GitHub. You have to fork to make changes. Fork. Files. public. src. constants.js. data.js. index.js....
Read more >How To Create Custom Components in React - DigitalOcean
Now that you have your project running, you can start making your custom component. In this step, you'll create an independent React component ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sir that is very smart. I have not thought of that.
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.