Fireship · @fireship
Next.js in 100 Seconds // Plus Full Beginner's Tutorial
Uploaded January 5, 2021 · Length 11:52
Summary
Learn Next.js fundamentals, server-side rendering, and data fetching in this beginner's tutorial.
- nextjs tutorial
- server-side rendering
- data fetching
- react framework
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:00
next js create fast search engine
- 0:02
optimize react apps with zero
- 0:04
configuration
- 0:05
a traditional react app is rendered
- 0:07
client side where the browser starts
- 0:09
with a shell of an html page
- 0:11
lacking any rendered content from there
- 0:13
the browser fetches the javascript file
- 0:14
containing the react code to render
- 0:16
content to the page
- 0:17
and make it interactive but there are
- 0:19
two major drawbacks with client-side
- 0:21
rendering
- 0:22
one the content is not reliably indexed
- 0:24
by all search engines
- 0:25
or read by social media link bots and
- 0:27
two it can take longer to reach the
- 0:29
first contentful paint when a user first
- 0:31
lands on the web page
- 0:32
next is a framework that allows you to
- 0:34
build a react app but render the content
- 0:36
in advance on the server
- 0:38
so the first thing a user or search bot
- 0:40
sees is the fully rendered html
- 0:42
after receiving this initial page
- 0:44
client-side rendering takes over
- 0:45
and it works just like a traditional
- 0:47
react app it's the best of both worlds
- 0:49
fully rendered content for bots highly
- 0:51
interactive content for users
- 0:53
inside of a next project you have a
- 0:54
pages directory each javascript file
- 0:56
defined here
- 0:57
exports a react component that
- 0:59
represents a route in the application
- 1:01
in other words the file structure here
- 1:03
mirrors the actual urls that the user
- 1:05
will navigate to
- 1:06
and next provides its own router to make
- 1:08
navigation seamless
- 1:09
but the real magic comes into play when
- 1:11
we talk about data fetching
- 1:12
because next can perform multiple server
- 1:14
rendering strategies from a single
- 1:16
project
- 1:17
static generation or pre-rendering
- 1:19
allows you to render your pages
- 1:21
at build time each page or component can
- 1:23
implement a function called
- 1:25
get static props it might fetch data
- 1:27
from a cloud database then pass the data
- 1:29
as props to the component
- 1:30
you can then build your app to render
- 1:32
out all the html locally
- 1:33
and upload it to a storage bucket where
- 1:35
it can be easily cached by a cdn
- 1:37
that works great for a blog or any kind
- 1:39
of app where the data doesn't change
- 1:41
often
- 1:41
but if the data does change often you
- 1:43
can implement server side rendering
- 1:45
which builds the html page
- 1:46
each time it's requested by the user in
- 1:49
the component we implement data fetching
- 1:51
with the get server side props function
- 1:53
instead of running at build time this
- 1:55
function runs at request time
- 1:56
that means the page will fetch the
- 1:58
latest data on the server each time a


