adrianhajdin / ecommerce_sanity_stripe

Modern Full Stack ECommerce Application with Stripe
https://jsmastery.pro
2.19k stars 675 forks source link

Products not showing up error #62

Open Alba1020 opened 2 years ago

Alba1020 commented 2 years ago

image I am getting this message when first hooking up sanity, it is not pulling up the products I have created with sanity.

marvelous-007 commented 1 year ago

did you give it a prop

peanutsee commented 1 year ago

As @marvelous-007 have suggested, you might have forgotten to pass in the products prop in your getServerSideProps function.

// Get Server Side Props: https://nextjs.org/docs/pages/building-your-application/data-fetching/get-server-side-props
export const getServerSideProps = async () => {
  // Sanity Query for Products
  const product_query = '*[_type == "product"]';
  const products = await client.fetch(product_query);

  // Sanity Query for Banner
  const banner_query = '*[_type == "banner"]';
  const banner = await client.fetch(banner_query);

  return {
    props: { products, banner },
  };
};

props: {products, banner} is where you want to check for this mistake.

Hope this helps :)