我曾经尝试过几次实施draftjs。但是,过了一段时间后,我今天再次尝试使用^ 0.10。*版本。
但是基于一个基本的例子,我得到一个常数错误:
Uncaught TypeError: blockRendererFn is not a function
at DraftEditorContents.render (index_bundle.js:113154)
at finishClassComponent (index_bundle.js:63203)
at updateClassComponent (index_bundle.js:63180)
at beginWork (index_bundle.js:63555)
at performUnitOfWork (index_bundle.js:65554)
at workLoop (index_bundle.js:65618)
at HTMLUnknownElement.callCallback (index_bundle.js:55872)
at Object.invokeGuardedCallbackDev (index_bundle.js:55911)
at invokeGuardedCallback (index_bundle.js:55768)
at renderRoot (index_bundle.js:65696
我认为blockrendererFn现在是强制性的。但是,我仍然无法弄清楚究竟是什么问题。
我正在遵循使用EditorState.createEmpty()
任何帮助将不胜感激。这是我的班级:
import React from 'react';
import {Editor,
EditorState,
DefaultDraftBlockRenderMap
} from 'draft-js';
import {Segment} from 'semantic-ui-react';
class MyTodoListEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createEmpty(),
};
this.onChange = (editorState) => this.setState({editorState});
}
render () {
return (
<Segment>
<Editor
editorState={this.state.editorState}
onChange={this.onChange}/>
</Segment>
);
}
}
Editor.propTypes = {};
Editor.defaultProps = {};
export default MyTodoListEditor;