Using promises to set the default value in config does not work #958
-
I am trying to load the content which should go inside of the editor from the backend, and then set it as the default value once I have it, however it does not work. I'm wondering how to overcome this? I won't be able to use const { get } = useEditor((root) =>
Editor.make()
.config(nord)
.config((ctx) => {
ctx.set(rootCtx, root);
ctx.set(editorViewOptionsCtx, { editable: () => editable });
loadContent().then(content => {
console.log(content); // This console logs the correct content
ctx.set(defaultValueCtx, content); // This does not set the default value
const listener = ctx.get(listenerCtx);
listener.markdownUpdated((ctx, markdown, prevMarkdown) => {
if (markdown !== prevMarkdown) {
saveContent(markdown);
}
})
});
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I recheck the code and find out that the async config is also supported. But you should return a promise or use async function. Editor.make()
.config(async (ctx) => {
const defaultValue = await fetchContent();
ctx.set(defaultValueCtx, defaultValue);
}) This should work. |
Beta Was this translation helpful? Give feedback.
Operations in config should be synchronized.I recheck the code and find out that the async config is also supported. But you should return a promise or use async function.
This should work.