This gist contains a util function I wrote for creating Editor.js plugins in React. The sample plugin is taken from this Editor.js tutorial.
As Editor.js current does not support React officially (See this issue), a lot of people are facing issues when trying to create an Editor.js plugin in React.
A common workaround is to:
- Create a div element in the constructor, and save it as a property:
constructor() {
this._container = document.createElement("div");
}
- Render your React component to the div element by:
ReactDOM.render(
createElement(<MyComponent/>, {
/* props */
}),
this._container
);
As this pattern is used so much, I extracted out this logic into a util function createEditorJsPlugin
. Hope it's useful!
ReactDOM.render is deprecated since React 18.0.0. How to use this in react 18