Last active
May 27, 2020 08:55
-
-
Save maitrungduc1410/baafe356f7fa3068381695afc2406a15 to your computer and use it in GitHub Desktop.
Editorjs
This file contains 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, { useRef } from 'react'; | |
import EditorJS from '@editorjs/editorjs' | |
const App = () => { | |
const editor = useRef() | |
const init = () => { | |
if (!editor.current) { | |
editor.current = new EditorJS({ | |
holder: 'editorjs', | |
minHeight: 0 | |
}) | |
} | |
} | |
const destroy = () => { | |
if (editor.current) { | |
editor.current.destroy() | |
} | |
} | |
const getData = async () => { | |
if (editor.current) { | |
try { | |
const outputData = await editor.current.save() | |
console.log(outputData) | |
console.log("JSON data", '\n') | |
console.log(JSON.stringify(outputData)) | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
} | |
return ( | |
<div className="App"> | |
<button onClick={init}>Init</button> | |
<button onClick={destroy}>Destroy</button> | |
<button onClick={getData}>Get data</button> | |
<div id="editorjs" style={{ border: 'solid 1px black' }}></div> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment