0

I am exporting a function which returns a function. Where I want to have another return statement with the previously returned function as shown.

export function fetchData(id) {

    return function(dispatch) {

        REST.jsonRestGet(`data/sos/${id}`, Data.prepareSosData(
                (data) => {
                 console.log(data);
                return data; // returns undefined
                }))
    }
}

While importing and calling this function into another component, it returns undefined.

Meana
  • 65
  • 1
  • 9

1 Answers1

0

It seems to be an asynchronous call. As the statement is executed asynchronously, it won't be returning anything. Also, the return statement inside the callback will return the value to the second argument only and not the variable you are expecting to.

You can use promises to get the returned data.

Nikhil Goyal
  • 1,945
  • 1
  • 9
  • 17