Skip to content
Advertisement

How to Inject new element in SlateJS Editor DOM

How to inject new react component/element into SlateJS Editor DOM?

I want to inject a new element within the SlateJS editor’s DOM, not above or below.

Most of SlateJS’s examples would transform nodes, but it doesn’t allow for direct injecting into the SlateJS DOM. That is within the editor context.

EG

JavaScript

Right now, you can add a new react component above or under the SlateJS editor, but not within.

JavaScript

My current solution is trying to inject via ReactDOM, but I’m having trouble getting the actual SlateJS component, since I can’t set the ID, making document.query difficult.

How could I inject a new react component within the SlateJS dom?

Advertisement

Answer

In the end, I injected the React component into the H1 div in Elements. Although, this method is buggy.

That is, keep everything the same in the Rich Text example except the elements, modified below.

Rich Text Example Line

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement