Playback starts YouTube’s embedded player (privacy-enhanced mode).
Next.js Tutorial - Part 8 | Static Site Generation (SSG) | getStaticProps and getStaticPaths
ChannelBruno AntunesChapters
Description from the creator
In this video, we will build an e-commerce website and learn how to use getStaticProps and getStaticPaths in Next.js to statically generate our website.
----
Repository: github.com/bmvantunes/youtube-2020-april-nextjs…
----
Next.js documentation: nextjs.org/docs/basic-features/data-fetching
Next.js Blog: nextjs.org/blog/next-9-3#next-gen-static-site-g…
----
Timeline:
00:00 Introduction to SSG
03:35 Setup SQLite
06:15 Using getStaticProps to create the Landing page
13:55 Using getStaticProps and getStaticPaths for the Details page
29:21 Styling with Material-UI
43:34 Adding pagination to the Landing page using getStaticProps and getStaticPaths
56:39 A challenge for you and conclusion
----
The next description is a "Copy-paste" from Next.js Blog Post + Documentation:
You should use getStaticProps if:
1. The data required to render the page is available at build time ahead of a user’s request.
2. The data comes from headless CMS.
3. The data can be publicly cached (not user-specific).
4. The page must be pre-rendered (for SEO) and be very fast — getStaticProps generates HTML and JSON files, both of which can be cached by a CDN for performance.
Because getStaticProps runs at build time, it does not receive data that’s only available during request time, such as query parameters or HTTP headers as it generates static HTML.
Write server-side code directly
Note that getStaticProps runs only on the server-side. It will never be run on the client-side. It won’t even be included in the JS bundle for the browser. That means you can write code such as direct database queries without them being sent to browsers. You should not fetch an API route from getStaticProps — instead, you can write the server-side code directly in getStaticProps.
Statically Generates both HTML and JSON
When a page with getStaticProps is pre-rendered at build time, in addition to the page HTML file, Next.js generates a JSON file holding the result of running getStaticProps.
This JSON file will be used in client-side routing through next/link (documentation) or next/router (documentation). When you navigate to a page that’s pre-rendered using getStaticProps, Next.js fetches this JSON file (pre-computed at build time) and uses it as the props for the page component. This means that client-side page transitions will not call getStaticProps as only the exported JSON is used.
----
Follow me on:
Twitter: twitter.com/bmvantunes
Dev.to: dev.to/bmvantunes
Website: brunoantunes.net
Github: github.com/bmvantunes
LinkedIn: linkedin.com/in/bmvantunes
----
Repository: github.com/bmvantunes/youtube-2020-april-nextjs…
----
Next.js documentation: nextjs.org/docs/basic-features/data-fetching
Next.js Blog: nextjs.org/blog/next-9-3#next-gen-static-site-g…
----
Timeline:
00:00 Introduction to SSG
03:35 Setup SQLite
06:15 Using getStaticProps to create the Landing page
13:55 Using getStaticProps and getStaticPaths for the Details page
29:21 Styling with Material-UI
43:34 Adding pagination to the Landing page using getStaticProps and getStaticPaths
56:39 A challenge for you and conclusion
----
The next description is a "Copy-paste" from Next.js Blog Post + Documentation:
You should use getStaticProps if:
1. The data required to render the page is available at build time ahead of a user’s request.
2. The data comes from headless CMS.
3. The data can be publicly cached (not user-specific).
4. The page must be pre-rendered (for SEO) and be very fast — getStaticProps generates HTML and JSON files, both of which can be cached by a CDN for performance.
Because getStaticProps runs at build time, it does not receive data that’s only available during request time, such as query parameters or HTTP headers as it generates static HTML.
Write server-side code directly
Note that getStaticProps runs only on the server-side. It will never be run on the client-side. It won’t even be included in the JS bundle for the browser. That means you can write code such as direct database queries without them being sent to browsers. You should not fetch an API route from getStaticProps — instead, you can write the server-side code directly in getStaticProps.
Statically Generates both HTML and JSON
When a page with getStaticProps is pre-rendered at build time, in addition to the page HTML file, Next.js generates a JSON file holding the result of running getStaticProps.
This JSON file will be used in client-side routing through next/link (documentation) or next/router (documentation). When you navigate to a page that’s pre-rendered using getStaticProps, Next.js fetches this JSON file (pre-computed at build time) and uses it as the props for the page component. This means that client-side page transitions will not call getStaticProps as only the exported JSON is used.
----
Follow me on:
Twitter: twitter.com/bmvantunes
Dev.to: dev.to/bmvantunes
Website: brunoantunes.net
Github: github.com/bmvantunes
LinkedIn: linkedin.com/in/bmvantunes
About this tutorial
Bruno Antunes published this 59:39 video tutorial on May 9, 2020. It has been watched 23,136 times on YouTube.
- Channel
- Bruno Antunes
- Category
- Science & Technology
- Duration
- 59:39
- Published
- May 9, 2020
- Views
- 23,136
- Likes
- 596
Tags
Share
This tutorial in other languages
- FRNext.js Tutorial - Partie 8 | Site statique Génération (GSS) | getStaticProps et getStaticPaths
- ESNext.js Tutorial - Parte 8 | Estática Generación del sitio (SSG) | getStaticProps y getStaticPaths
- PTNext.js Tutorial - Parte 8 | Estática Geração Site (SSG) | getStaticProps e getStaticPaths
- ITNext.js Tutorial - Part 8 | Static Generation sito (SSG) | getStaticProps e getStaticPaths
- DENext.js Tutorial - Teil 8 | Statische Site-Generation (SSG) | getStaticProps und getStaticPaths
- NLNext.js Tutorial - Deel 8 | Statische site Generation (SSG) | getStaticProps en getStaticPaths
- RUNext.js Учебник - Часть 8 | Статическая поколение сайта (SSG) | getStaticProps и getStaticPaths
- PLNext.js Tutorial - Część 8 | Statyczne strony Generation (SSG) | getStaticProps i getStaticPaths
- JANext.jsチュートリアル - パート8 |静的サイト生成(SSG)| getStaticPropsとgetStaticPaths
- ARNext.js دروس - الجزء 8 | الجيل الموقع ثابت (SSG) | getStaticProps وgetStaticPaths
- HINext.js ट्यूटोरियल - भाग 8 | स्टेटिक साइट पीढ़ी (एसएसजी) | getStaticProps और getStaticPaths
- IDNext.js Tutorial - Part 8 | Generasi Site statis (SSG) | getStaticProps dan getStaticPaths