Next.js Flashcards

(65 cards)

1
Q

What does React render to create web pages?

A

JSX and TSX code. Next.js provides another way to do this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some key benefits of Next.js over React?

A

Improved initial page load performance, SEO, and user experience on slow devices/networks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two rendering methods for JSX/TSX code?

A

Client Side Rendering (CSR) and Server Side Rendering (SSR).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does Client Side Rendering (CSR) work?

A

JSX/TSX is compiled to JavaScript and sent to the browser, which renders the webpage by manipulating the DOM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does Server Side Rendering (SSR) work?

A

JSX/TSX is rendered to HTML on the server and sent to the browser with minimal JavaScript for reactivity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which rendering methods does React support?

A

Only Client Side Rendering (CSR).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which rendering methods does Next.js support?

A

Both CSR and SSR. By default it performs SSR.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a major drawback of CSR?

A

Slow initial page load due to downloading and executing a large JavaScript bundle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a major benefit of SSR?

A

Faster initial loading as the browser receives pre-rendered HTML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is hydration in Next.js?

A

The process of running JavaScript on the HTML received from SSR to make the page interactive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you specify a component to use CSR in Next.js?

A

Add ‘use client’ at the top of the component file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How has the role of React changed with the emergence of Next.js?

A

React is often used within frameworks like Next.js instead of standalone.

React is a library that lets you put components together, but it doesn’t prescribe how to do routing and data fetching. To build an entire app with React, we recommend a full-stack React framework like Next.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What command creates a new Next.js project?

A

Use the terminal and run: npx create-next-app@latest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does routing mean in Next.js?

A

Handling a client’s request based on its URL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two routers in Next.js?

A

Pages Router and App Router.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which Next.js router supports React’s latest features?

A

The App Router.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you containerise a Next.js project?

A

Add Dockerfile and .dockerignore, then use docker build and docker run commands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the RootLayout component responsible for?

A

Formatting common to every page, like buttons and banners.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the Home component define?

A

The specific content for the route, using CSR.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Where do you define routes using the App Router?

A

In the app directory using folders and files.
A route is a single path of nested folders, following the file-system hierarchy from the root folder down to a final leaf folder that includes a page.js file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a URL segment?

what is a URL path?

A

Part of a URL path delimited by slashes. Each folder in the nested hierarchy represents a route segment

Part of the URL that comes after the domain (composed of segments).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you create a nested route like /dashboard/settings?

A

You build a directory structure inside the app directory that mimics the route structure you want to be able to visit.

Nest folders: app/dashboard/settings/page.js.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you define a dynamic route segment in Next.js?

A

You use dynamic segments, that are filled in at request time or pre rendered at build time.

Use square brackets in folder names [folderName], e.g., [id] or [slug].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How are dynamic segment values accessed?,

A

They are passed as the params prop to layout/page functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Give an example of a dynamic route for a blog post.
app/blog/[slug]/page.js
26
What is the purpose of the layout file in Next.js?
Shared UI for a segment and its children
27
What does the page file define in Next.js?
The unique UI of a route; makes the route publicly accessible
28
What does the loading file do in Next.js?
Provides a loading UI for a segment and its children
29
What is the use of the not-found file?
Defines the "not found" UI for a segment and its children
30
What does the error file handle?
Displays UI for errors in a segment and its children (React error boundary)
31
What does the global-error file handle?
Displays global error UI
32
What is the purpose of the route file?
Creates a server-side API endpoint
33
What is the function of the template file?
Specialised re-rendered Layout UI
34
What is the default file used for?
Fallback UI for Parallel Routes
35
Which file extensions can be used for special files in Next.js?
.js, .jsx, or .tsx
36
What is the rendering order of special files?
layout > template > error > loading > not-found > page/nested layout
37
What happens in a nested route?
Child components are nested inside parent segment components
38
What is colocation in Next.js?
Storing related files (e.g. components, styles) within app folders
39
Are non-special files like button.js routable?
No, only page.js or route.js make folders routable
40
What are Parallel Routes?
Show multiple pages in the same view with independent navigation
41
What are Intercepting Routes?
Show one route in the context of another (e.g. task detail in task list)
42
What are Route Handlers in Next.js?
Custom API endpoints using web standard APIs
43
What HTTP methods are supported by Route Handlers?
GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
44
What does force-dynamic do?
Forces dynamic rendering for each user request
45
Can route.js exist at the same level as page.js?
Route Handlers can be nested inside the app directory, like page.js and layout.js but there cannot be a route.js file at the same route segment level as page.js as the app.router won’t know if you want to serve that route as a web page or an API endpoint.
46
How is caching handled by default for GET in Route Handlers?
Next.js caches the result of the GET request
47
How to opt out of caching in GET requests?
Use the Request object with GET, or use other HTTP methods, or dynamic functions
48
What is the fetch function in JavaScript?
Fetches data via HTTP and returns a Promise
49
What is a promise and what are the states of a Promise?
A promise is a javascript object that returns immediately, telling the CPU that it's working on it/has status pending and it will soon return the promised data or a failed status. Pending, Fulfilled, Rejected
50
What does await do in JavaScript? Where must await be used?
Pauses execution until a Promise is resolved. Inside an async function
51
What do the Promise methods .then() and .catch() do?
.then() to handle successful outcomes and .catch() to handle errors - This allows you to chain asynchronous operations and manage errors more cleanly than traditional methods.
52
How does async function behave?
Non-blocking (await suspends the execution of an async function) and always returns a Promise
53
What does the fetch API allow in POST requests?
Sending data to a server using headers and a JSON body
54
Name 4 ways to fetch data in Next.js
Server with fetch, server with 3rd-party libraries, client via Route Handler, client with 3rd-party libraries
55
What is Data Caching in Next.js?
Storing data so it doesn’t need to be fetched every time
56
When is fetch not cached?
Inside POST Route Handlers, Server Actions, after headers/cookies
57
What is force-cache?
The default caching mode in fetch
58
What is the Data Cache in Next.js?
Persistent HTTP cache shared across regions
59
What is Revalidation?
purging the Data Cache and re-fetching the latest data
60
What are two types of revalidation?
Time-based and On-demand
61
How to set time-based revalidation?
Automatically re-validate data after a certain amount of time has passed Use next: { revalidate: } in fetch command
62
How to do on-demand revalidation
Manually re-validate data based on an event Use revalidatePath or revalidateTag in Server Actions or Route Handlers
63
What happens if revalidation fails?
The last successfully generated data will continue to be served from the cache. On the next subsequent request, Next.js will retry revalidating the data.
64
How to disable caching for a fetch request?
Use cache: 'no-store'
65
What is the recommended way to control caching?
Configure each fetch request individually for granularity