0

I'm trying to return a text value I get from a endpoint. But keep getting the promise. Here is what I have tried. And admins please dont close this as I dont understand the answer from the other post about promises.

const test = fetchEnglishFilterValue(language, selectedFilter.key, selectedFilter.value).then((response): void => {
    if (response.status === StatusCodes.Success) {
        response.text().then((responseValue: string):string => {
            return responseValue;
        });
    } else {
        error("some error");
    }
});
        
const test2 = test;
console.log(test2);
ComCool
  • 773
  • 4
  • 15
  • 28
  • 2
    Look closely, you're not returning anything from `fetchEnglishFilterValue`. – Richard Dunn Jul 16 '21 at 22:39
  • More specific duplicate: [Why is my asynchronous function returning Promise { } instead of a value?](https://stackoverflow.com/questions/38884522/why-is-my-asynchronous-function-returning-promise-pending-instead-of-a-val) – Ivar Jul 16 '21 at 22:41

0 Answers0