Created
March 23, 2021 22:02
-
-
Save joao-pedrozo/669b7c3d9679424b9bc52f06a0dfb5fe to your computer and use it in GitHub Desktop.
Draft.js with toolbar and ERROR when toolbar's button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use Editor from draft-js plugins
import Editor from '@draft-js-plugins/editor';