uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.17k stars 156 forks source link

Programmatic field clearing does not work correctly #176

Closed RomanChumakov closed 3 years ago

RomanChumakov commented 3 years ago

Hello! I found that when setting the md-editor value programmatically, md-editor appears to be half-cleared. The Markdown is cleared immediately. But the Textarea is not cleared until I switch to the preview mode and then back to previous mode. It looks like the Textarea is not updated when the value is changed directly, until it is refreshed by changing mode.

jaywcjlove commented 3 years ago

@RomanChumakov Can you provide a reproducible example?

RomanChumakov commented 3 years ago

I created a simple example using creat-react-app here: https://github.com/RomanChumakov/react-md-editor-bug-demonstration I also recorded a video based on this example

https://user-images.githubusercontent.com/25747120/119963670-ce8ef200-bfc1-11eb-9007-ee752466209d.mp4

jaywcjlove commented 3 years ago

https://github.com/RomanChumakov/react-md-editor-bug-demonstration/blob/97ab1b703d3d6ee22630ac5f6375d04b796532fa/src/App.js#L22

<MDEditor
    className = "product-md-editor"
    onChange = {value => formik.setFieldValue('text', value)}
-    value = {formik.values.text}
+    value = {formik.values.text || ''}
/>

@RomanChumakov

jaywcjlove commented 3 years ago

@RomanChumakov

Or, Upgrade + @uiw/react-md-editor@3.3.2

RomanChumakov commented 3 years ago

@jaywcjlove Thank you for such a quick response!