facebookarchive / draft-js

A React framework for building text editors.

Home Page:https://draftjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: _ref is undefined

AxtinM opened this issue · comments

commented

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
editorKey="SimpleInlineToolbarEditor"
editorState={editorState}
onChange={onChange}
plugins={plugins}
ref={(element) => {
editor.current = element;
}}
/>


);
};

export default SimpleInlineToolbarEditor;
`

commented

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

commented

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