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 => {
console.log(response)
}).catch(error => {
console.log(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?
The TypeError object represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type. A TypeError may be thrown when: an operand or argument passed to a function is incompatible with the type expected by that operator or function; or.
What is TypeError in Python? TypeError is an exception in Python programming language that occurs when the data type of objects in an operation is inappropriate. For example, If you attempt to divide an integer with a string, the data types of the integer and the string object will not be compatible.
According to the Mozilla website for developer documents, “the TypeError object represents an error when a value is not of the expected type.” Uncaught means that the error was not caught in the catch part of the try-catch block.
The React. js "Uncaught TypeError: X is not a function" occurs when we try to call a value that is not a function as a function, e.g. calling the props object instead of a function. To solve the error, console. log the value you are calling and make sure it is a function. Here is an example of how the error occurs.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With