TypeError: # is not iterable

I was trying to use promise.all to do multiple api calls but for some reason it it throwing the following error

TypeError: # is not iterable

My Promise is fairly simple (this is probably the second time I am using Promise.all)

componentWillMount() {
    const id = this.props.location.pathname
    let axiosHome = axios.get('/home')
    let axiosUserData = axios.get("/profile/" + id)
    Promise.all(axiosHome,  axiosUserData).then(response => {
    }).catch(error => {

Question: Any idea why I could be getting this error? Also, can someone also explain when is that we use resolve keyword with promise?

Promise.all accepts a single argument, which is an array of Promises – subsequent arguments are discarded. So, pass in an array instead:

Promise.all([axiosHome,  axiosUserData])

when is that we use resolve keyword with promise?

resolve is not a keyword, it’s just the conventional function name used when constructing a Promise:

const prom = new Promise((resolve, reject) => {
  // do some asynchronous stuff
  if (ok) resolve();
  else reject();

When a Promise is explicitly constructed like that, call resolve() to resolve the Promise. (of course, one could name the function argument anything, it doesn’t have to be called resolve)

Promise.all() accepts arrays of methods (async) and data can be assign to variables
as array


let [axiosHomeData , axiosUserData] = await Promise.all([axiosHome,  axiosUserData]);

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   setTimeout() inside JavaScript Class using "this"

Similar Posts