Jungwoo-An / react-editor-js

โš›๏ธ๐Ÿ“The unofficial editor-js component for React
https://codesandbox.io/s/react-editor-js-v2-34bfl
MIT License
954 stars 77 forks source link

Inject block programmatically? #180

Closed orbachar closed 2 years ago

orbachar commented 2 years ago

Hi I wonder if is there a way to inject a new block to editor js, programmatically, from an outside event, while allowing to edit the content with the regular behavior of onChange prop.

the way I though of doing that, was to listen to onChange prop as usual, get the blocks on save, and when an outside event happens, push a new block to the content returned from onChange, and pass it on value prop. Unfortunately using both value and onChange props cause infinite loop.

I wonder if is there another way achieving that?

Jungwoo-An commented 2 years ago

@orbachar Hi! First of all, thanks for your interest! ๐Ÿ‘‹

Can you show me an example of the use case?

Thanks!

orbachar commented 2 years ago

eventually I managed to make it work by using the editor core instance and use it's render function to update the editor content externally

image