【发布时间】:2023-01-27 19:04:45
【问题描述】:
我正在使用 lexical 并想为编辑器设置初始文本。
现在,我只是想硬编码初始文本。原来我不能只传递一个字符串。
它需要是 JSON 格式。
因此,我改为传递以下内容。
'{"text":"sample text"}'
但它抛出以下错误:
类型错误:无法读取未定义的属性(读取“类型”)
我究竟做错了什么?
function Placeholder() { return <div className="editor-placeholder">Enter some rich text...</div>; } const editorConfig = { // This is how I am trying to set initial value. // no errors if I remove this. I need this cos I need to set initial value. editorState: '{"text":"sample text"}', // other params }; export default function Editor() { return ( <LexicalComposer initialConfig={editorConfig}> <div className="editor-container"> <ToolbarPlugin /> <div className="editor-inner"> <RichTextPlugin contentEditable={<ContentEditable className="editor-input" />} placeholder={<Placeholder />} /> {/* other login components */} </div> </div> </LexicalComposer> ); }
【问题讨论】:
标签: javascript next.js lexicaljs