tinymce / tinymce-react

Offical TinyMCE React component
MIT License
959 stars 156 forks source link

editor doesn't update controlled variable #320

Closed RotateAt60MPH closed 2 years ago

RotateAt60MPH commented 2 years ago

What is the current behavior?

Edited text does not save to react-controlled variable.

Please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox.io or similar.

sandbox

What is the expected behavior?

Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or tinymce-react?

"@tinymce/tinymce-react": "^3.13.1",

Worked previously in older version (unknown).

exalate-issue-sync[bot] commented 2 years ago

Ref: INT-2793

tiny-james commented 2 years ago

You have an error in the name of the event handler prop. It should be onEditorChange not handleEditorChange. Additionally if you are going to set the initialValue you must ensure that it is only set once, if you change it the editor will reset to that value so never use the same source as the value prop. The reason that initialValue now causes a reset is that it allows the value to be loaded asynchronously as previously the initialValue had to be set before the editor was loaded.

I have updated your example to fix the name of onEditorChange and to set initialValue from the prop so it doesn't change with typing. https://codesandbox.io/s/tinymce-react-forked-zpgenl?file=/src/index.js

RotateAt60MPH commented 2 years ago

Very much obliged. Cheers!