What is the correct way to return data from a Promise? I have the following code:
const axios = require("axios").default;
async function getApiData(pathName: string, locale: string) {
const {axiosRequestUrl} = getApiVars(pathName, locale);
const axiosClient = axios.create({
baseURL: process.env.CONTENT_DOMAIN,
proxy: false
})
return await axiosClient.get(axiosRequestUrl);
}
export default function getPageData() {
getApiData('shared-content', 'en-us')
.then((data) => {
return data;
})
.catch((error: any) => {
// log error here
})
}
but if I try to use getPageData
from a component I end up with a void
function that does not return anything, why? What I am missing here?