Next.js Discord

Discord Forum

How to make static sit generation dynamic (runtime, not build time)?

Answered
Orinoco Crocodile posted this in #help-forum
Open in Discord
Orinoco CrocodileOP
As the title says. During build time, some APIs are unavailable. How to make SSR pages render when they are deployed (and by the way frequently re-render when the API responses change, say every 5 minutes) and opt out of generation at build time? How do you guys deal with that?
Answered by Ray
yes, export const dynamic = 'force-dynamic'; will opt-out static generate for the page.
and you could use set the cache for the fetch to revalidate the data in 5min like this
fetch(`https://...`, { next: { revalidate: 300 } })
View full answer

2 Replies

Orinoco CrocodileOP
Looks like export const dynamic = 'force-dynamic'; on the page seems to be the solution. Would appreciate a peer confirmation if possible!
@Orinoco Crocodile Looks like `export const dynamic = 'force-dynamic';` on the page seems to be the solution. Would appreciate a peer confirmation if possible!
yes, export const dynamic = 'force-dynamic'; will opt-out static generate for the page.
and you could use set the cache for the fetch to revalidate the data in 5min like this
fetch(`https://...`, { next: { revalidate: 300 } })
Answer