instructure-react / react-tinymce

React TinyMCE component
181 stars 110 forks source link

Editor disappear if the parent component updates the state. #92

Closed AlexKvazos closed 4 years ago

AlexKvazos commented 6 years ago

So the component that renders the editor has the onChange handler and updates the state with the new value each time an input changes, however, the editor disappears when this happens. Looks like the render function is making the editor disappear. Any ideas?

elijahmanor commented 4 years ago

I had this same problem. I tracked down the problem and internally an init handler was getting triggered and would set the contents to "" after it had the correct value.

So, in my consuming code I ended up adding a setup method inside of the config that is passed to TinyMCE. In the setup I listen to the init event and manually set the editor's contents.

Something like this... (pseudo-code)

<TinyMCE
  content={ content }
  config={ {
    setup( editor ) {
      editor.on( "init", () => editor.setContent( content ) )
    }
  } }
/>