3

I'm building an ecommerce shop in Nextjs and (headless) Shopify. I want all my pages to be statically generated. For that I use getStaticProps & getStaticPaths (of course) where I mainly fetch product data from the Shopify API. I'm having a lot of pages where the product data is needed or at least part of it: product overview, collection pages, filter pages, product detail page an so on.

Now I wonder if I should do this API call (getting all products) only once and store it somewhere:

Could I handle it (3000 products) as a global state using recoil or something similar? But I want this state only on server side.

L. Heider
  • 1,579
  • 1
  • 14
  • 31
  • You're using statically generated pages, meaning the API call will be done on the server at build time. Do you mean you want to cache the API's response during build time so you don't have to make that request every time to statically generate all the pages? – juliomalves Nov 07 '21 at 13:09
  • Yes, but rather I'm looking for a convenient way to use this data in all the pages (that will be statically generated) without having to call the API more than once (for one build). I'd use recoil or some other state management, but I don't want to have the state (products array) on client side - only on server side. – L. Heider Nov 08 '21 at 07:49
  • 1
    Recoil and other React state management libraries are for managing state in React, on the client-side. What you need here is a way to cache the data from the request you do on the server (`getStaticProps`/`getStaticPaths`). – juliomalves Nov 08 '21 at 11:16

0 Answers0