niuware / mui-rte

Material-UI Rich Text Editor and Viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to auto-save notes

mosofsky opened this issue · comments

Checklist

Description

I cannot figure out a way to save the MUIRichTextEditor's value automatically to a database when onChange is fired. I tried a solution that "debounced" the save to the database using lodash.debounce. However, saving to the database causes React to re-rerender the component that contains the MUIRichTextEditor. Since I'm using the defaultValue of MUIRichTextEditor to display what's in the database, the cursor insertion point gets reset to the beginning of the text field. I understand that is because "every time you change the value property you are actually resetting the editor" (issue 52).

I tried another solution where I render MUIRichTextEditor with defaultValue as long as the content is not dirty (i.e. onChange has not been called). However, I did that by sometimes rendering MUIRichTextEditor with defaultValue and sometimes without defaultValue. That did not work at all because React saw these as two completely different components.

So, is there a way to use MUIRichTextEditor where onChange saves the data to a database but not more frequently than say 5 seconds (i.e. debounced)?