Open altumsoftwareds opened 1 year ago
If I will pass expected data directly as prop ( not waiting for response ) -- there is no issues at all.
@neSpecc could you help, please? 1)
2)
1) onChange triggers with empty data however current answer
is exists and it rewrites answer to be empty
2) even after some additional rerenders of component ( as soon as I get requested from BE data from props ) current answer
becomes correct again, but editor doesn't rerenders with correct answer ( data ) object
<Editor
key={`editor-${section}-${item}`}
data={answer}
onChange={(data) => {
console.log('editor beforeOnChange answer', answer)
console.log('editor onChange', data)
setAnswer(data)
}}
editorblock={`editorjs-container-${section}-${item}`}
/>
why I don't see current answer
after onChange
as soon as I have setAnswer
which is the part of useState
?
@altumsoftwareds would you test in it 2.29.0-rc.4
?
I am not sure if this is related, I am getting the same "warning" when I put editor.save()
method inside the onChange
function. However It is fine when I trigger editor.save()
somewhere else
editor = new EditorJS({
holder : 'summary',
onChange: function(api, event) {
editor.save().then(console.log)
}
});
@ls84 where to put editor.save()
else, for example?
@ls84 where to put
editor.save()
else, for example?
I am guessing the problem of Block «paragraph» skipped because saved data is invalid
is caused by saving data before it's ready to be saved out. My solution was to bind editor.save()
to a button click action. Hope this helps
It's because the Paragraph delays saving its data to element. And the save function makes data from its element. (And the warning occurs when the element has empty body)
requestAnimationFrame
causes the problem.
There are two solutions.
1) Override the Paragraph and remove 'requestAnimationFrame' logic.
2) Save using requestAnimationFrame
inside onChange. This will make the save is called after hydrate. (FIFO)
I am waiting when I will get response with some structure and I need to pass it to Editor.
( I also see such error in console:
Block «paragraph» skipped because saved data is invalid
)so on initial render editor triggers
onChange
method with empty data{time: 1697134792817, blocks: Array(0), version: '2.28.0'}
( I tested it using setTimeout )and it overrides data I save in useState. That's why I see empty editor.
Full code :