chore: plain text plugin for Editor (#17134)

* chore: plain text plugin for Editor

* fix build error
This commit is contained in:
Anik Dhabal Babu authored and GitHub committed 2024-11-11 20:23:12 +05:30
1 parent aaa75100d4
commit cd15335eed
4 files changed
+34 -9

No files matched your search

@@ -0,0 +1,27 @@
"use client";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { $getRoot } from "lexical";
import { useEffect } from "react";
type PlainTextPluginProps = {
setText: (text: string) => void;
plainText: boolean;
};
export default function PlainTextPlugin({ setText, plainText }: PlainTextPluginProps) {
const [editor] = useLexicalComposerContext();
useEffect(() => {
return editor.registerUpdateListener(({ editorState }) => {
editorState.read(() => {
if (plainText) {
const textContent = $getRoot().getTextContent();
setText(textContent);
}
});
});
}, [plainText]);
return null;
}