Jungwoo-An / react-editor-js

⚛️📝The unofficial editor-js component for React
https://codesandbox.io/s/react-editor-js-v2-34bfl
MIT License
945 stars 77 forks source link

Difficulty with loading defaultValue blocks #170

Closed gonsaje closed 2 years ago

gonsaje commented 2 years ago

Environment

Describe

I am trying to implement react-editor with pre-existing document templates. It seems that when I try to use the defaultValue prop in the ReactEditorJS component, nothing is displayed.

Code:

`

const dummyTemplate = [
  {
    data: { level: 2, text: 'Company Name:' },
    type: 'header',
  },
  { data: { level: 4, text: 'Date:' }, type: 'header' },
];

const ReactEditorJS = createReactEditorJS();
const editorJS = useRef(null);
const handleInitialize = useCallback((instance) => {
    editorJS.current = instance;
}, []);

// return

 <ReactEditorJS
        defaultValue={temp}
        onInitialize={handleInitialize}
        tools={EDITOR_JS_TOOLS}
/>

`

I think I'm a little confused as to how the defaultValue should be configured.

Thanks in advance, Jungwoo!

gonsaje commented 2 years ago

I found out that we need to pass the entire editor object instead of just the blocks array. Thank you anyways

robertseghedi commented 9 months ago

How did you solve this? It's still unclear for me

robertseghedi commented 9 months ago

Nevermind, sorry for the reply.

For anyone having the same problem, take a look in here: https://codesandbox.io/s/react-editor-js-v2-34bfl?file=/src/index.js:365-5051 to understand the way the property is built. You have to pass the entire object. I was saving in my database only the blocks.