Noob question about fetching data
Unanswered
Texas leafcutting ant posted this in #help-forum
Texas leafcutting antOP
Hi all 🙂
Got a noob question as I'm learning (more) about Next.js on the fly.
I'm fetching data (see below) and trying to access it in my component. However, the data won't show? Upon console.log'ing, I see it's
So I have two questions, actually
1. How can I 'know' what the type is of the returned props, namely
2. Maybe if I know 1 I know 2, but still sometimes a bit lost with
Any help is much appreciated! 🙂
Got a noob question as I'm learning (more) about Next.js on the fly.
I'm fetching data (see below) and trying to access it in my component. However, the data won't show? Upon console.log'ing, I see it's
undefined. No idea why. Again, prolly a rookie mistake but I'm just trying to understand (:export const fetchData = async () => {
// From the Sanity tutorial, trying to fetch pets
const pets = await client.fetch(`*[_type == "pet"]`);
return {
props: {
pets,
},
};
};So I have two questions, actually
1. How can I 'know' what the type is of the returned props, namely
pets. Because I'm using TS2. Maybe if I know 1 I know 2, but still sometimes a bit lost with
undefined and all, why is it undefined? Any help is much appreciated! 🙂
3 Replies
you need to use
getServerSideProps() in a page to allow prefetching data of a page