nextjs Flashcards

1
Q

What is the problem with SPAs?

A

The first load takes a long time before the user can do anything at all

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

What are the 5 steps that the spa’s do to render a html page

A
request html
html return with a div and some js
js downloads other js files
requests to the rest server
finally render the page
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Since server-side rendering fixes the SPA’s first load issue, what are the problem with server-side js?

A

not all js runs on the server
event lifecycle is diff on the server
async call completion gets tricky

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

Which framework can solve few of the spa’s issues but keeping its great ux?

A

nextjs

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

how to manually install next js?

A
mkdir my-next-prj && cd my-next-prj
npm init
npm install react react-dom nextjs --save
create a pages folder with an index.js
then run the next command
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

where to put nextjs configs?

A

in the .next folder in a file called next.config.js

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

How does the server-side rendering work? 5 steps

A

nodejs runs js
react is started and all components ctors run
component render methods called
all rendered static html is sent to client browser

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

How does the client-side rendering works? 6 steps

A
html downloaded from server
script tags download js files
js executes including all react comps
comp constructors run
*component lifecycle events such as componentDidMount run*
component render methods called
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is html mistmatch warning and what does it mean? What side effect does it cause?

A

warning that means that the server html is diff than the client html. cause the app to be re-render client-side (app still work but with overhead).

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

How to solve the html mismatch warning?

A

by using the getInitialProps which passes the initial state along with the server-side-rendered html (the first load) meaning that the client-side instead of creating its own initial state (e.g new Date()) it is going to use the server-side-generated on which is encoded within the __NEXT_DATA object.

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

What problem can the getInitialProps() cause? What should we avoid doing with it?

A

The component is only constructed after the getInitialProps is completed, even if the getInitialProps returns a promise. It means we have to be careful with what is executed inside this method (make sure it runs fast)

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

What happens if I change the BROWSER url to /sessions? How to avoid going to the server?

A

The sessions page is SERVER-SIDE rendered. By using a nextjs link component that does a client-side routing (needs to be a link somewhere in the page).

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

What happens if I change the BROWSER url to /sessions? How to avoid going to the server?

A

The sessions page is SERVER-SIDE rendered. By using a nextjs link component that does a client-side routing (needs to be a link somewhere in the page).

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

where to put images and other static content?

A

in the static folder and its subfolders

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

How to name the files inside the pages dir? How to name the page’s main react component?

A

index.js = lower case so can be accessed localhost:3000

export const Index = pascal case

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

where to add cross-page components such as header, nav and footer?

A

in the _app.js file using regular react syntax