0

I'm using firestore to create records

const add = db.collection("people").add({name: "test"})

this returns a promise and then I do something like

add.then(person => console.log(person))

I need to convert that promise to a synchronous function because I can´t use then() to trigger a link. (looks like a browser limitation for this particular use case)

if (add(...) {
    console.log("would like to use the person here but since is not a promise I don´t know how")
}

const add = (data) => {
    return data
}

const result = add(1);
if (result) {
    console.log(result)
} else {
    console.log("no result")
}
handsome
  • 2,335
  • 7
  • 45
  • 73
  • 1
    What do you mean by trigger a link? Cause a link's click event to be triggered, or it's native action(navigate to some url)? Both you can do from inside a promise's `then()` callback. You cant go from async to some sync code, the closest is using async/await syntax – Patrick Evans Apr 23 '20 at 19:30
  • I did the investigation and I´m getting different results if i put the document.location inside a resolved promise. looks like the browser knows that the action is not generated by the user but a result of a function. is weird I know. – handsome Apr 23 '20 at 19:36

0 Answers0