Next.js Flashcards
In Next.js, what is a page?
In Next.js, a page is a React Component exported from a file in the pages directory.
What does the Link component enable in Next.js ?
The Link component enables client-side navigation between two pages in the same Next.js app.
What is client side navigation?
Client-side navigation means that the page transition happens using JavaScript, which is faster than the default navigation done by the browser.
Next.js does code splitting automatically, what does this mean?
Next.js does code splitting automatically, so each page only loads what’s necessary for that page. That means when the homepage is rendered, the code for other pages is not served initially.
How do you link to an external page outside the Next.js app?
If you need to link to an external page outside the Next.js app, just use an <a> tag without Link.</a>
What is cumulative layout shift? How is this related to Next.js?
It is a core web vital that google uses in search ranking.
Cumulative Layout Shift (CLS) is an important, user-centric metric for measuring visual stability because it helps quantify how often users experience unexpected layout shifts—a low CLS helps ensure that the page is delightful.
Next.js has an image component that optimizes images. It loads the image in a way that avoids any layout shift.
What is hydration?
Hydration is when a prerendered HTML page receives the JavaScript to make it fully functional. The HTML page initially loads with very little JavaScript.
From the Next.js starting guide
Each generated HTML is associated with minimal JavaScript code necessary for that page. When a page is loaded by the browser, its JavaScript code runs and makes the page fully interactive. (This process is called hydration.)
What is pre rendering in Next.js ?
This is when a pre-rendered HTML page is loaded first and then the JavaScript (React code) that makes it functional is loaded after. This gives the page load the appearance of being very fast.
Next.js has two forms of pre-rendering, what are they?
Static Generation and Server-side Rendering.
What is Static Generation?
Static Generation is the pre-rendering method that generates the HTML at build time. The pre-rendered HTML is then reused on each request.
What is Server-side rendering?
Server-side Rendering is the pre-rendering method that generates the HTML on each request.
When deciding whether you should use static generation what question should you ask yourself?
You should ask yourself: “Can I pre-render this page ahead of a user’s request?” If the answer is yes, then you should choose Static Generation.
When is static generation not a good idea?
On the other hand, Static Generation is not a good idea if you cannot pre-render a page ahead of a user’s request. Maybe your page shows frequently updated data, and the page content changes on every request.
What is static generation with data?
This is when a static HTML page is generated but some data that goes into it is retrieved before it is generated .
How do you use static generation with data?
when you export a page component, you can also export an async function called getStaticProps. If you do this, then:
getStaticProps runs at build time in production, and…
Inside the function, you can fetch external data and send it as props to the page.