I am trying to fetch some data from a free api https://catfact.ninja/fact
using axios in nextjs but getting promise pending.
httpClient.js:
import axios from "axios";
const GET_CATS = "https://catfact.ninja/fact";
export const getCats = async () => {
try {
return await axios.get(GET_CATS);
} catch (e) {
console.log("ERROR", e.message);
}
};
index.js:
import { getCats } from "./api/httpClient";
const Home = ({ data }) => {
console.log(getCats());
return <div></div>;
};
export default Home;
So i am confused why the promise is not resolving as i am already async
await
the api call in httpClient.js