每日進度 1 Flashcards

1
Q

come out with a picture of react life cycle

A
  • 2 phases and their 特性
  • 3 steps and life cycle methods
  • “need to remember where to put [ React updates DOM and refS ] “
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the 特性 of the render phase?

A
  1. pure and no side effects here
  2. may be below 3 -ed by React // for Updating especially
    - 2.1. Paused
    - 2.2. Aborted
    - 2.3. Restarted // i.e. calling this.setState()、forceUpdate()、new props come in
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what may trigger re-start rendering?

A

calling

    1. this.setState()
    1. forceUpdate()
    1. new props come in
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

which phase does [ React updates DOM and refS ] live ?

A

it lives in [ commit phase ]

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

mounting starts before?

A

components/elements are on our DOM

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

what does constructor do?

A
  • “know” props and states

- state initialized

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

what does render do?

A

“know” the html (jsx) to show

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

where to put api calls in Mounting?

A

componentDidMount

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
[why] [api calls] stay in componentDidMount?
// hint: think of what will happen if we call apis
A

cuz we want to have [the base component]

  • before loading data
  • and updating the component (re-render)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

react won’t do what 2 things and why?

A
  1. react [won’t re-mount] the component
  2. react [won’t re-create] the element
    - cuz they are too costly to a browser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what’s the [chain reaction] of a component gets [re-renderd] ? and what’s the problem of it ? also, what’s the solution of it ?

A
  1. “re-render” [the component]
  2. “re-render” the component’s [child componentS]
    - 可能太浪費效能
    - solution: shouldComponentUpdate ?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what’s the possible problem of [re-rendering] ? and what’s the solution of it ?

A
  • 可能太浪費效能

- solution: shouldComponentUpdate

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

the thought of code of shouldComponentUpdate ? and why we need to do that (2) ?

A

return this.props.$prop !== nextProps.$prop;

  1. for performance mainly
  2. if they are the same, then there is no reasons to re-render
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

[which] part is so important / fundamental for us to become a good react developer ?

A
  • updating phase

- shouldComponentUpdate

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

[why] updating phase or shouldComponentUpdate is important to us (2) ?

A

一、cuz it’s related to

  1. how [code is structured] in [a component]
  2. how [the architecture of a react project] is
    - they [are based around updating phase]

二、updating is fundamentally React Lib Does for us

三、this is why we [break our code up] into componentS

四、React’s updating phase makes our life easier…

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

which 2 parts [are based around updating phase] that is so fundamental for us to become a great react developer?

A
  1. how [code is structured] in [a component]

2. how [the architecture of a react project] is

17
Q

what is React Lib fundamentally do for us?

A

updating

18
Q

why we break our code up into componentS?

A

react data flow、updating

- 因為React最主要幫我們做的就是 handle the updating by [ its data flow ] // 這也是為什麼我們需要React

19
Q

which phase react does for us makes our life easier?

A
  • updating phase

- react handles the updating by [ its data flow / React Data Flow ]

20
Q

react updates [the DOM / Components] based on what [inside of our components] ? also, what it will trigger ?

A

一、react updates [the DOM / Components] based on

  • new props coming in
  • this.setState()
  • forceUpdate()

二、what it will trigger
- this triggers [ a chain reaction ], like updating our component and its child components (not only render itself, but also re-render any child components it has)

21
Q

which part of lifecycle methods is the method we can leverage on [to allow us possibly improve the performance of our application] ?

A
  • to update / updating, [ shouldComponentUpdate ] is the lifecycle method that we can leverage to possibly [improve the performance] of our application
  • it also gives us a better idea of [ when we should do what with our components ]
22
Q

which part of lifecycle methods gives us a better idea of [ when we should do what with our components ] ?

A

shouldComponentUpdate in updating phase in react component life cycle

23
Q

shouldComponentUpdate give us what kind of idea ?

A

it gives us the idea like [ “when” we should do “what” with our components ] for [ improving performance ] to components / our app