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

Getting Promise<pending> in console

It is a React (Ts) project and I am getting a Promise<Pending> problem when I try to get request in Axios. Thank you in advance for your help!

import axios from 'axios';

interface song {
  name: string;
}

interface playlist {
  playlistname: string;
  songs: song[];
}

async function getsongs(): Promise<song[]> {
  const url = 'https://be-ask.tanaypratap.repl.co/playlist';
  const response = await axios.get<playlist>(url);
  return response.data.songs;
}

export const finaldata = getsongs();

>Solution :

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

Since getsongs is also async function, it will return a promise, and thus when you print finaldata, it consoles Promise.

Not sure what you are trying to achieve but if you just want to print the data, print after the await in the function getsongs.

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