You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
執行到 useState 時,會更新 fiber node 中的 state(計算待執行佇列),接著回傳目前版本的 state 值,存進 component local variable 成為 snapshot
回傳 state 值不會再做 shallow clone,而是直接回傳值並存在 function component 內的區域變數;也因為是直接回傳,如果 state 是物件型別,就要避免 mutate,不然跨 render 的 state 值就會被影響,因為是 mutate fiber node 裡面的同一個 reference
state 不用做 shallow clone 是因為不會有多個 state 一起包成一個物件,而是各自的值(e.g. count 的 state 值、number 的 state 值)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
《React 思維進化》讀書會第二組 4-1~4-3
簡報
4-2 Function component 與 class component 關鍵區別
『function component 會自動捕捉該次 render 時的 props 與 state 資料』是什麼意思?
{ number: xxx }
)傳給 fiber node,紀錄最新的 propsObject.freeze
以避免被更改,Object.freeze
是針對複製出來的這一份資料useState
時,會更新 fiber node 中的 state(計算待執行佇列),接著回傳目前版本的 state 值,存進 component local variable 成為 snapshot延伸問題:為什麼 useRef 回傳的值會是 Object?
QA
function component 和 class component 差異
this
上,而this
可能被修改,this
是取得這物件上最新的屬性值;而 function component 則是直接回傳 propsthis
可能被修改,props 本身還是 immutable 的觸發生命週期的時機
Unmount 過程中,是先移除 DOM 元素還是先執行 cleanup function?
component 不能自己 unmount 自己
Unmount 有 render phase 和 commit phase 嗎?
Beta Was this translation helpful? Give feedback.
All reactions