티스토리 뷰

다른 예제를 보면 대략적으로 만들수는 있는데 값을 html 값으로 변환은 다음과같다.

 

console.log('editorState =>',draftToHtml(convertToRaw(editorState.getCurrentContent())) )

반대로 draft로 변환하는 것은 다음과 같다.(Axios로 서버에서 import하여 화면에 표시할때)

 

const blocksFromHtml = htmlToDraft(boardResult[0].content);
        if (blocksFromHtml) {
            const {contentBlocks, entityMap} = blocksFromHtml;
            // https://draftjs.org/docs/api-reference-content-state/#createfromblockarray
            const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap);
            // ContentState를 EditorState기반으로 새 개체를 반환.
            // https://draftjs.org/docs/api-reference-editor-state/#createwithcontent
            const editorState = EditorState.createWithContent(contentState);
            setEditorState(editorState); // <== 이부분 
        }
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함