How to fetch dynamic data on pre-rendered routes? #11718
Unanswered
visakadivines
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now I'm rendering a product page (
/pages/product
) via getStaticProps which contains links (dynamic routes) to product detail pages (/pages/product/[name]
) for each respective product that I'm pre-rendering using getStaticPaths. As you can imagine a lot of product information (image, name, price, etc.) are static, however, things like stock or status (available, out-of-stock, etc.) are dynamic. What I'm trying to do is fetch this dynamic data via SWR on the pre-rendered route (product detail page), but am encountering the following error:Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
In
/pages/product/[name]
:I'm a bit unclear as to what this error means and if there exists a way to fetch this dynamic data via SWR. I believe the Incremental Static Generation RFC could solve my problems as I can fetch stock and status at build time and revalidate every couple of minutes. However, I was wondering if there was a way to fetch this information in the meantime. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions