I want to create text editor in React.js app, using react-editor-js. However I cannot get this module working on a functional component. My code roughly looks like this:
import { createReactEditorJS } from "react-editor-js";
import { EDITOR_JS_TOOLS } from "./EditorConstants";
const ReactEditorJS = createReactEditorJS();
const CreateNewPost = () => {
const { t } = useTranslation();
const [editorValue, setEditorValue] = useState({
time: new Date().getTime(),
blocks: [
{
type: "header",
data: {
text: "Testing title",
level: 2
}
},
{
type: "paragraph",
data: {
text:
"We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏"
}
},
],
version: "2.1.0"
});
return (
<div className={style.wrapper}>
<div className={style.container}>
{/*TITLE*/}
<div className={style.titleContainer}>
<label>{t("post.postTitle")}</label>
<input type="text"/>
</div>
<div>
<ReactEditorJS
tools={EDITOR_JS_TOOLS}
data={editorValue}
/>
</div>
</div>
</div>
)
}
export default CreateNewPost;
The result - there is no any editor on the page. How to make it working?
This example uses class component and editor is working. While the same will not work on a functional component.