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就可以了
浙公网安备 33010602011771号