3

I wrote a separate function to convert html to draftjs, there I used htmlToDraft function from html-to-draftjs.

The Function:

const htmlToDraftBlocks = (html) => {
    const blocksFromHTML = htmlToDraft(html);
    const state = ContentState.createFromBlockArray(
      blocksFromHTML.contentBlocks,
      blocksFromHTML.entityMap
    );
    const editorState = EditorState.createWithContent(state);
    return editorState;
  };

when running the server in node.js I get the following error:

ReferenceError : window is not defined

I have tried bellow way as well:

let htmlToDraft = null;
if (typeof window !== 'undefined') {
  htmlToDraft = require('html-to-draftjs').default;
}

But in this case htmlToDraft remains null, not getting imported.

Why I am getting this error? Any help is appreciated

Radhushani
  • 31
  • 2
  • `window` exists only in the browser. if your app is running on the server, then there is no `window` object – Boguz Nov 28 '22 at 15:03

0 Answers0