showing results for - " axios2 default all is not a function"
Diego
17 Feb 2019
1// Seems to be related to a babel transpile issue
2// Workaround - create a separate instance of axios
3// Cause - 'all' is not a function of the instance of axios. See: https://github.com/axios/axios#instance-methods
4
5const axiosInstance = axios.create(/*{
6  baseURL: 'https://some-domain.com/api/',
7  timeout: 1000,
8  headers: {'X-Custom-Header': 'foobar'}
9}*/);
10
11// Create get requests using axios instance
12const requestOne = axiosInstance.get("https://jsonplaceholder.typicode.com/todos/1");
13const requestTwo = axiosInstance.get("https://jsonplaceholder.typicode.com/todos/2");
14const requestThree = axiosInstance.get("https://jsonplaceholder.typicode.com/todos/3");
15
16// Call 'all' on axios directly
17axios.all([requestOne, requestTwo, requestThree])
18  .then((responses) => {
19    // Both requests are now complete
20    console.log(responses);
21  }).catch(errors => {
22    // react on errors.
23  });