Skip to content

Instantly share code, notes, and snippets.

@joao-pedrozo
Created March 23, 2021 22:02
Show Gist options
  • Save joao-pedrozo/669b7c3d9679424b9bc52f06a0dfb5fe to your computer and use it in GitHub Desktop.
Save joao-pedrozo/669b7c3d9679424b9bc52f06a0dfb5fe to your computer and use it in GitHub Desktop.
Draft.js with toolbar and ERROR when toolbar's button
import React, { useEffect } from 'react';
import { Editor, EditorState } from 'draft-js';
import { useState } from 'react';
import 'draft-js/dist/Draft.css';
import createToolbarPlugin from '@draft-js-plugins/static-toolbar';
const staticToolbarPlugin = createToolbarPlugin();
const { Toolbar } = staticToolbarPlugin;
const PostReview = () => {
useEffect(() => {
setState(true);
}, []);
const [state, setState] = useState(false);
const [editorState, setEditorState] = React.useState(() =>
EditorState.createEmpty(),
);
const handleOnChange = (editorState) => {
setEditorState(editorState);
};
return (
<div
style={{
border: '1px solid black',
minHeight: '6em',
cursor: 'text',
marginTop: '10px',
}}
>
{state && (
<>
<Editor
editorState={editorState}
onChange={handleOnChange}
plugins={[staticToolbarPlugin]}
/>
<Toolbar />
</>
)}
</div>
);
};
export default PostReview;
@sibelius
Copy link

use Editor from draft-js plugins

import Editor from '@draft-js-plugins/editor';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment