Advertisement
danine1

Multiple Axios API requests

Mar 9th, 2019
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   componentDidMount() {
  2.     axios
  3.       .all([
  4.         axios.get("https://swapi.co/api/people"),
  5.         axios.get("https://swapi.co/api/planets")
  6.       ])
  7.       .then(
  8.         axios.spread(function(peopleRes, planetRes) {
  9.           //... but this callback will be executed only when both requests are complete.
  10.           console.log("People", peopleRes.data);
  11.           console.log("Planets", planetRes.data);
  12.           peopleRes.data.results.map(result => ({
  13.             name: `${result.name}`,
  14.             id: result.id
  15.           }));
  16.         })
  17.       );
  18.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement