Having recently "graduated" to using Promises, I worked up this pattern that absolutely does work, but I'm wondering if it is "technically" correct, or "best practices"? GetAsync()
is a function that makes a fetch()
call to an API endpoint and receives back a JSON response.
new Promise((resolve, reject) => {
GetAsync("../api/CurrentUserAccount", resolve, reject, "json")
})
.then((result) => {
// code that does stuff with the user account json
});
Again, this works just fine, but doing it this way, I am never doing anything with either resolve
or reject
. That makes me think "I'm doing this wrong." Is there a better, or more proper way to do this?