It's important to note that this question is specifically related to next.js. Understanding Next.js is crucial for grasping the interaction between the getStaticProps
and Home
functions as shown in the code snippet below.
export async function getStaticProps() {
const dummyData = [
{
id: '1',
name: 'john'
},
{
id: '2',
name: 'Tom'
}
];
return {
props: { data:dummyData }
};
}
export default function Home({ data }) {
console.log(data);
return (
<ul>
<li>USER</li>
{data && data.map((user) => (
<li key={user.id}>
{user.name}
</li>
))}
</ul>
);
}
I have attempted to pass data to the Home
function through getStaticProps
, but the console.log
displays undefined
.
My goal is to successfully retrieve the data from getStaticProps().