Skip to content

Instantly share code, notes, and snippets.

@maitrungduc1410
Last active May 27, 2020 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maitrungduc1410/baafe356f7fa3068381695afc2406a15 to your computer and use it in GitHub Desktop.
Save maitrungduc1410/baafe356f7fa3068381695afc2406a15 to your computer and use it in GitHub Desktop.
Editorjs
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