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