Can't get the html value using $generateHtmlFromNodes on onChange Editor prop
Nhed1 opened this issue · 4 comments
Describe the bug
Uncaught Error: Unable to find an active editor state. State helpers or node methods can only be used synchronously during the callback of editor.update() or editorState.read().
To Reproduce
....
const handleChange = (state, editor) => {
editor.update(() => {
const htmlString = $generateHtmlFromNodes(editor, null);
console.log(htmlString);
});
};
return (
<EditorComposer>
<Editor hashtagsEnabled={true} onChange={handleChange}>
....
Expected behavior
To return the HTML value from the text editor when onChange is called
Desktop (please complete the following information):
- OS: Windows 11
- Browser Chrome
Any solution? Isn't html output #1 feature of the component and bug got no attention?
people dealing with same problem here:
https://stackoverflow.com/questions/73062801/convert-lexical-to-html
there some solution inthere but it is for useEffect
If we export the LexicalComposer context to the user to wrap in their app, we can then access the correct state that will allow us to run $generateHtmlFromNodes from anywhere within that context.
Ah... I figured it out, you need to use Lexcial v0.8.0 for current version (0.5.0 on npm).