Currently, I am utilizing lexical and aiming to establish initial text for the editor.
At the moment, my approach involves hardcoding the initial text, but it seems I cannot simply pass a String as anticipated.
Instead, the format required is JSON. Hence, I am providing the following input:
'{"text":"sample text"}'
However, this results in an error being thrown:
TypeError: Cannot read properties of undefined (reading 'type')
What could be the issue in my implementation?
function Placeholder() {
return <div className="editor-placeholder">Enter some rich text...</div>;
}
const editorConfig = {
// This is how I am attempting to specify the initial value.
// No errors occur if I omit this. However, it's necessary for setting the initial value.
editorState: '{"text":"sample text"}',
// other parameters
};
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>
);
}