That is, can I statically generate a header and main content using SSR
Asked
Active
Viewed 696 times
0
-
1Check https://stackoverflow.com/questions/73812425/does-nextjs-prerender-all-pages-or-only-the-first-page/73812572#73812572 – JeanJacquesGourdin Sep 28 '22 at 07:39
1 Answers
3
Unfortunately, you can't achieve such a thing with pure next.js.
As stated in their docs for SSR:
getServerSideProps can only be exported from a page. You can’t export it from non-page files.
Same goes for SSG:
getStaticProps can only be exported from a page. You cannot export it from non-page files, _app, _document, or _error.
You can only use next.js data-fetching on page level.

Zakaria Benali
- 298
- 2
- 5
-
"You can only use next.js data-fetching on page level." I think it can be it's better if you clarify, you can fetch data in a component, you cannot fetch data that will be used as props for a page anywhere else than on the said page. – JeanJacquesGourdin Sep 28 '22 at 12:56
-
1Hello, @JeanJacquesGourdin Thanks for the clarification, the term "next.js data-fetching" is mostly referred to the data-fetching (rendering) methods provided by next.js which are (SSG, SSR, ISR, and CSR). However, the question isn't related specifically to fetching data, but more to using different next.js rendering methods for each component in a page (component level) which is not possible. – Zakaria Benali Sep 28 '22 at 13:21