facebookarchive / draft-js

A React framework for building text editors.
https://draftjs.org/
MIT License
22.56k stars 2.64k forks source link

TypeError: _ref is undefined #3148

Closed AxtinM closed 2 years ago

AxtinM commented 2 years ago

Uncaught TypeError: _ref is undefined

this happens when i press delete key (<---)

image ` import React, { ReactElement, useEffect, useMemo, useRef, useState, } from "react"; import { EditorState } from "draft-js"; import Editor, { createEditorStateWithText } from "@draft-js-plugins/editor"; import createInlineToolbarPlugin from "@draft-js-plugins/inline-toolbar"; import "../../../styles/editorStyles.css"; import "@draft-js-plugins/inline-toolbar/lib/plugin.css"; const text = "In this editor a toolbar shows up once you select part of the text …";

const SimpleInlineToolbarEditor = (): ReactElement => { const [plugins, InlineToolbar] = useMemo(() => { const inlineToolbarPlugin = createInlineToolbarPlugin(); return [[inlineToolbarPlugin], inlineToolbarPlugin.InlineToolbar]; }, []);

const [editorState, setEditorState] = useState(() => createEditorStateWithText("") );

useEffect(() => { setEditorState(createEditorStateWithText(text)); }, []);

const editor = useRef<Editor | null>(null);

const onChange = (value: EditorState): void => { setEditorState(value); };

const focus = (): void => { editor.current?.focus(); };

return (

{ editor.current = element; }} />

); };

export default SimpleInlineToolbarEditor; `

AxtinM commented 2 years ago

this happens when i press delete key (<---)

AxtinM commented 2 years ago

i solved it by adding import { DraftailEditor } from "draftail"; and wrapping plugins Editor with DraftailEditor