So I wanted to check out this new rich text editor Editor, https://editorjs.io/
I installed the unofficial reactJS version, but I'm not quite sure what I'm doing wrong here... https://www.npmjs.com/package/react-editor-js
Has any used this before? can it be done with hooks? my thinking is that I need to define an instance of this editor so I can save the data. because currently onChange the editor is not adding any new blocks to the data object or the entered data.
also, if I passed the data object as an empty object in the console does not show an initial EditorJs block.
any help would be appreciated.
function App() {
let data = { '1': 'test' }
return (
<div className="App">
<EditorJs
data={data}
onChange={(e) => console.log(data)}
tools={{
code: Code,
header: Header,
paragraph: Paragraph
}}
/>
</div>
);
}
Editor. js is is not a react component. So we can create a wrapper component that takes care of managing the life cycle of editor.
We consider WebStorm to be the best-paid IDE on the market for React development, thanks to its many features, plugins, and good documentation.
The easiest way to use the react-monaco-editor with create-react-app is to use the react-app-rewired project. For setting it up, the following steps are required: Install react-app-rewired : npm install -D react-app-rewired. Replace react-scripts by react-app-rewired in the scripts section of your packages.
Draft. js is a framework for building rich text editors in React, powered by an immutable model and abstracting over cross-browser differences. Draft.
You can do this with hooks, write it like this:
const YourComponent = () => {
const instanceRef = useRef(null)
async function handleSave() {
const savedData = await instanceRef.current.save()
console.log(savedData)
}
And when you put the component in the return function do it like this:
<EditorJS
instanceRef={(instance) => (instanceRef.current = instance)}
tools={EDITOR_JS_TOOLS}
data={data}
/>
And don't forget to import useRef from react
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With