how to conditionally use getStaticProps?
Answered
Transvaal lion posted this in #help-forum
Transvaal lionOP
One question: assume i want to use previously saved data if a user navigates to a page inside the app and i want to use the get method inside the getStaticProps if a user clicks on the given link to go to that page.
How do I go about doing it? i'm attempting to ignore the call inside the static properties, however it gets called every time a user tries to use an app to navigate the page.
How do I go about doing it? i'm attempting to ignore the call inside the static properties, however it gets called every time a user tries to use an app to navigate the page.
Answered by joulev
as i said it's just fetching (or [prefetching](https://nextjs.org/docs/pages/api-reference/components/link#prefetch)) the page html.
getStaticProps is not run during those navigation11 Replies
@Transvaal lion One question: assume i want to use previously saved data if a user navigates to a page inside the app and i want to use the get method inside the getStaticProps if a user clicks on the given link to go to that page.
How do I go about doing it? i'm attempting to ignore the call inside the static properties, however it gets called every time a user tries to use an app to navigate the page.
getStaticProps is run during build time, it's not rerun when someone visits the page whether by browser native navigation or client-side router navigation
in dev mode then getStaticProps is always run when you visit the page, but in prod mode (
npm run build && npm start) that doesn't happen@joulev getStaticProps is run during build time, it's not rerun when someone visits the page whether by browser native navigation or client-side router navigation
Transvaal lionOP
hm gotcha, but in the network tab i'm seeing a request each time i try to navigate to the given page through app?
@Transvaal lion hm gotcha, but in the network tab i'm seeing a request each time i try to navigate to the given page through app?
[assuming prod mode] ah yes of course the browser needs to make a request to get the html of the page when you navigate to that page. it's static though and the getStaticProps function is not run at that time
@joulev [assuming prod mode] ah yes of course the browser needs to make a request to get the html of the page when you navigate to that page. it's static though and the getStaticProps function is not run at that time
Transvaal lionOP
hm, mind checking here https://jokerace.xyz/contest/polygon/0xE8653864addD6105D930B1aa06F9D149a547af0E ? sorry if offending, but could be easier for me to learn with you here.
in the network tab, i'm seeing on each click on these boxes underneath submissions, a network request to get the data for these dialogs. however it isn't needed in this case as i've already am supplying it with store data
in the network tab, i'm seeing on each click on these boxes underneath submissions, a network request to get the data for these dialogs. however it isn't needed in this case as i've already am supplying it with store data
@Transvaal lion hm, mind checking here https://jokerace.xyz/contest/polygon/0xE8653864addD6105D930B1aa06F9D149a547af0E ? sorry if offending, but could be easier for me to learn with you here.
in the network tab, i'm seeing on each click on these boxes underneath submissions, a network request to get the data for these dialogs. however it isn't needed in this case as i've already am supplying it with store data
as i said it's just fetching (or [prefetching](https://nextjs.org/docs/pages/api-reference/components/link#prefetch)) the page html.
getStaticProps is not run during those navigationAnswer
@joulev as i said it's just fetching (or [prefetching](<https://nextjs.org/docs/pages/api-reference/components/link#prefetch>)) the page html. `getStaticProps` is **not** run during those navigation
Transvaal lionOP
oh right gotcha! so we have a way to disable
prefetch right?@Transvaal lion oh right gotcha! so we have a way to disable `prefetch` right?
check the page i linked it could perhaps be helpful for your case
Transvaal lionOP
will do, thanks!
Transvaal lionOP
this worked @joulev
i was using
i was using
router and custom solution rather than using Link component and now it is always prefetching while cards are in the viewport, which solves my problem! will gladly tip youthanks for the tip and glad it worked