1

I'm still new to ReactJS and I'm having trouble doing an asyn await with dependencies from another request on axios.

I need to get a list of pokemon, this list returns me the name of pokemons.

With this list of names, I need to make another request, where I will pass this name that I received as a parameter.

In addition to passing the name as a parameter, I need to make a call with axios.get() using .map(). Because there are several calls I need to make. It is possible?

However, I am not able to do that. Can you tell me what I'm doing wrong?

Here's my code I put into codesandbox.io

import React from "react";
import axios from "axios";
import "./styles.css";

const App = () => {
  const BASE_URL = "https://pokeapi.co/api/v2";

  const getAllPokemons = async () => {
    const { data } = await axios.get(`${BASE_URL}/pokemon`);

    // Here is my pokemon list
    console.log(data);

    data.results.map((poke) => getPokeType(poke));
  };

  const getPokeType = async (poke) => {
    const { data } = await axios.get(`${BASE_URL}/type/${poke.name}`);

    console.log("data: ", data);
  };

  React.useEffect(() => {
    getAllPokemons();
  }, []);

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
};

export default App;

enter image description here

Thank you very much in advance.

Katyellen
  • 225
  • 2
  • 8
  • Get a [real devtools console](https://webmasters.stackexchange.com/q/8525), not that broken builtin thing. You're getting lots of 404 http errors, because `\`${BASE_URL}/type/${poke.name}\`` doesn't exist. Why not just fetch `poke.url` instead? – Bergi Jun 25 '22 at 16:45
  • Hi Bergi, I don't understand what do u mean. – Katyellen Jun 25 '22 at 18:54

0 Answers0