Why when I use the getData() it shows it as empty, but works when I fetch without it?
// "use client";
export default async function Home() {
async function getData() {
const res = await fetch("https://jsonplaceholder.typicode.com/posts");
return await res.json();
}
const res = await fetch("https://jsonplaceholder.typicode.com/posts");
const data = await res.json();
return (
<>
Why this shows an empty data {} : {JSON.stringify(getData(), null, 2)}
And this not: {JSON.stringify(data, null, 2)}
</>
);
}
Using NextJS with app folders