I'm trying to return a value from a function with a Promise, but I keep getting undefined,
export const checkForAgent = (language, country) => {
return new Promise((resolve, reject) => {
jsonp(
`https://example.com/status?language=${language}&country=${country}`,
null,
(err, data) => {
if (err) {
console.error(err.message);
reject("There was a problem!");
} else {
resolve(data.status);
}
}
);
});
};
I'm calling the promise as follows:
const status = checkForAgent("de", "ch");
console.log("status: ", status);
and in the console I'm getting
status: Promise {<pending>}
I need to just get data.status from this function,
any help would be appreciated.