DEV Community

loading...

dealing with async method calls

krisrajzlive profile image Raj ・1 min read

newNote is optional and if available should be pushed to notes colleciton via reducer using addProjectNotes function hook. The createProject methods seems called before the addProjectNotes completes execution and Notes collection is always blank. How can I call createProject only after addProjectNotes is fully executed?

'''
if (projectData.newNote) {
addProjectNotes(addNote(projectData.newNote))
}
createProject(projectData, setIsSubmitting, submittedCallback);
'''

Discussion (1)

Collapse
vasylnahuliak profile image
vasylnahuliak

Hello. You can use async/await.

const nameYourFunction = async () => {
if (projectData.newNote) {
await addProjectNotes(addNote(projectData.newNote))
}
createProject(projectData, setIsSubmitting, submittedCallback);
}

Forem Open with the Forem app