Draft js. Persist EditorContent to database

后端 未结 4 1751
南旧
南旧 2020-12-25 12:23

I\'m trying to persist draft-js\'s EditorContent to database then read and recreate the EditorContent object again. But EditorContent.getPla

4条回答
  •  一生所求
    2020-12-25 13:14

    I've found that I must stringify and parse the RawContentState object when reading and saving to the database.

    import { convertFromRaw, convertToRaw } from 'draft-js';
    
    // the raw state, stringified
    const rawDraftContentState = JSON.stringify( convertToRaw(this.state.editorState.getCurrentContent()) );
    // convert the raw state back to a useable ContentState object
    const contentState = convertFromRaw( JSON.parse( rawDraftContentState) );
    

提交回复
热议问题