Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Axios multiple then's

So I have a problem, I want so that this Axios returns me second then, and it doesn’t work, and I can’t understand why. So this second then returns me undefined, but I wanted to get ID from that or any data, any suggestions? I checked some other posts, they seemed to have the same writing, but for me it just doesn’t work, help pls:)

If you want to check Axios, at the end write ?q=Grimm (for example).
So the full page is: https://api.tvmaze.com/singlesearch/shows?q=Grimm

      .get('https://api.tvmaze.com/singlesearch/shows', {
        params: {
          q: id,
        },
      })
      .then((res) => setOneShow([res.data]))
      .then((res) => console.log(res));

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In a .then() chain, the second then block gets data returned from the first then block.

In your case, to get the same data in the second then block, alter your code as:

  axios.get("https://api.tvmaze.com/singlesearch/shows", {
        params: {
          q: id
        }
      })
      .then((res) => {
        console.log("1", res);
        return res;
      })
      .then((res) => console.log("2", res));
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading