Skip to content
Discussion options

You must be logged in to vote

runOnBackend takes two arguments, the function to run, and the arguments array to pass to said function. You need to pass your arguments in so they can be serialized over to the backend context.

Try doing something like this:

async function setNoteContent(noteID, content) {
        await api.runOnBackend((id, newContent) => {
            const targetNote = api.getNote(id);
            targetNote.setContent(newContent, null);
         }, [noteID, content]);
                
        await api.waitUntilSynced();
}

Think of the function you pass as being stringified (because it is), so the wrapping function's parameters are not actually in scope when the function runs.

Edit: Updated the varia…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sottey
Comment options

@zerebos
Comment options

@zadam
Comment options

zadam Sep 5, 2023
Maintainer

Answer selected by sottey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants