Answers for "_axios2.default.all is not a function"

0

_axios2.default.all is not a function

// Seems to be related to a babel transpile issue
// Workaround - create a separate instance of axios
// Cause - 'all' is not a function of the instance of axios. See: https://github.com/axios/axios#instance-methods

const axiosInstance = axios.create(/*{
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
}*/);

// Create get requests using axios instance
const requestOne = axiosInstance.get("https://jsonplaceholder.typicode.com/todos/1");
const requestTwo = axiosInstance.get("https://jsonplaceholder.typicode.com/todos/2");
const requestThree = axiosInstance.get("https://jsonplaceholder.typicode.com/todos/3");

// Call 'all' on axios directly
axios.all([requestOne, requestTwo, requestThree])
  .then((responses) => {
    // Both requests are now complete
    console.log(responses);
  }).catch(errors => {
    // react on errors.
  });
Posted by: Guest on September-24-2020

Code answers related to "_axios2.default.all is not a function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language