React中遇到htmlToDraft is not a function的解决方案
作者:互联网
报错具体代码如下
useEffect(()=>{
const html = props.content
const contentBlock = htmlToDraft(html);
if(html === undefined) return;
if (contentBlock) {
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);
const editorState = EditorState.createWithContent(contentState);
seteditorState(editorState)
}
},[props.content])
报错如下
Uncaught (in promise) TypeError: (0 , html_to_draftjs__WEBPACK_IMPORTED_MODULE_4__.htmlToDraft) is not a function
1、这是因为htmlToDraft版本兼容问题,把版本降为1.4.0
就可以了
2、加入一行代码htmlToDraft = require('html-to-draftjs').default
就可以了
标签:function,const,htmlToDraft,contentBlock,React,html,报错,draftjs 来源: https://www.cnblogs.com/Miya277/p/16101863.html