Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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));
like image 543
ApnikaPanika Avatar asked Feb 01 '26 14:02

ApnikaPanika


1 Answers

Check this lessons: Arrow Functions, Promises. You are calling and returning setOneShow() in your first .then() method, not res. How it should looks like:

axios.get('https://api.tvmaze.com/singlesearch/shows', {
   params: {
     q: id,
   },
 })
 .then((res) => {
   setOneShow([res.data]);
   return res;
 })
 .then((res) => {
   console.log(res);
 });
like image 166
Oybek Odilov Avatar answered Feb 04 '26 04:02

Oybek Odilov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!