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 :
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.