Setting OnChange to Plate makes Editor onfocusable #3600
-
Hello Community! Code snippet: type plateTextEditorProps = {
/**
* External Onchange
*/
onChange?: (value: Value) => void;
};
export function RichTextEditor({
onChange = () => { },
}: plateTextEditorProps) {
const localValue =
typeof window !== 'undefined' && localStorage.getItem('editorContent');
return (
<TooltipProvider>
<Plate editor={editor} onChange={({ value }) => {
localStorage.setItem('editorContent', JSON.stringify(value));
onChange(value as Value);
}}>
<FixedToolbar>
<FixedToolbarButtons withModeSelect={withModeSelect} />
</FixedToolbar>
<Editor />
<FloatingToolbar>
<FloatingToolbarButtons />
</FloatingToolbar>
</Plate>
</TooltipProvider>
); My previous implementation did not use the local storage at all, this is something I now added following the new instructions for setting up Plate. If anyone has any tips or knows a way to get the value from the editor from the outside without using OnChange help would be greatly appreciated! My requirements are that I only need to access the JSON data when submitting a form in which the editor is embedded. With best regards, |
Beta Was this translation helpful? Give feedback.
Looks like you forgot to use
useMemo
. The editor is being re-created on each re-render. Or you could useusePlateEditor
that is memoized.