I have an component that needs to store the editor data whenever it has changed. I am using the onChange function but besides the actual data which I can get via (const body = await api.saver.save(); or a ref as shown in the docs), I need to add a changing temporary id (changingTemporaryId in the example below) to the onChange function, but this value seem to be stale and doesn't change even if the surrounding value has. Is it possible to pass a changing variable to onChange or EditorJS?
Example:
function ReactComponent() {
const changingTemporaryId = Math.random().toString().substring(2);
const handleOnChange = async (api) => {
const body = await api.saver.save();
console.log(changingTemporaryId); // This value is stale and doesn't get updated with re-renders.
fetch('/api/sections', {
method: 'POST',
body: JSON.stringify({body, changingTemporaryId}),
});
};
return <Editor onChange={handleOnChange} />
}
I have an component that needs to store the editor data whenever it has changed. I am using the
onChange
function but besides the actual data which I can get via (const body = await api.saver.save();
or aref
as shown in the docs), I need to add a changing temporary id (changingTemporaryId
in the example below) to theonChange
function, but this value seem to be stale and doesn't change even if the surrounding value has. Is it possible to pass a changing variable toonChange
orEditorJS
?Example: