Next.js Discord

Discord Forum

Noob question about fetching data

Unanswered
Texas leafcutting ant posted this in #help-forum
Open in Discord
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 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 TS
2. 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