每日進度 1 Flashcards
come out with a picture of react life cycle
- 2 phases and their 特性
- 3 steps and life cycle methods
- “need to remember where to put [ React updates DOM and refS ] “
what are the 特性 of the render phase?
- pure and no side effects here
- 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
what may trigger re-start rendering?
calling
- this.setState()
- forceUpdate()
- new props come in
which phase does [ React updates DOM and refS ] live ?
it lives in [ commit phase ]
mounting starts before?
components/elements are on our DOM
what does constructor do?
- “know” props and states
- state initialized
what does render do?
“know” the html (jsx) to show
where to put api calls in Mounting?
componentDidMount
[why] [api calls] stay in componentDidMount? // hint: think of what will happen if we call apis
cuz we want to have [the base component]
- before loading data
- and updating the component (re-render)
react won’t do what 2 things and why?
- react [won’t re-mount] the component
- react [won’t re-create] the element
- cuz they are too costly to a browser
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 ?
- “re-render” [the component]
- “re-render” the component’s [child componentS]
- 可能太浪費效能
- solution: shouldComponentUpdate ?
what’s the possible problem of [re-rendering] ? and what’s the solution of it ?
- 可能太浪費效能
- solution: shouldComponentUpdate
the thought of code of shouldComponentUpdate ? and why we need to do that (2) ?
return this.props.$prop !== nextProps.$prop;
- for performance mainly
- if they are the same, then there is no reasons to re-render
[which] part is so important / fundamental for us to become a good react developer ?
- updating phase
- shouldComponentUpdate
[why] updating phase or shouldComponentUpdate is important to us (2) ?
一、cuz it’s related to
- how [code is structured] in [a component]
- 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…