TypeError: #<Promise> is not iterable
Promise.all
accepts a single argument, which is an array of Promise
s - subsequent arguments are discarded. So, pass in an array instead:
Promise.all([axiosHome, axiosUserData]) .then(...
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 variablesas array
Example:
let [axiosHomeData , axiosUserData] = await Promise.all([axiosHome, axiosUserData]);