Reduce returns empty array

49 views Asked by At

For some reason when the function below is called, it returns "UNDEFINED".

We checked and the accumulator returns what it should (We tried printing to log what it holds, and it is a list of items) but the "reduce" function returns an empty array.

(We tried saving its value into an array and printing it to log, it was empty "{}").

Here is the code:

createItemsList = (order: Order) => {
    return order.items.reduce((accumulator: { [key: string]: Item }, item) => {
        let promiseItem = api.getItem(item.id);
        promiseItem.then(currItem => accumulator[item.id] = currItem);
        return accumulator;
    }, {});
};

Any ideas?

0

There are 0 answers