2

搞懂 React 中的 state 和 props

 2 years ago
source link: https://blog.niclin.tw/2018/11/18/%E6%90%9E%E6%87%82-react-%E4%B8%AD%E7%9A%84-state-%E5%92%8C-props/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nic Lin's Blog

喜歡在地上滾的工程師

  • props 意味著父級分發下來的屬性
  • state 是組件內部可以自行管理的狀態

數據沒辦法向上回溯,只能單向向下分發,或者自行內部管理消化。

  • props 對於 component 來說是「immutable」不可改變的
  • state 則是「mutable」可以改變的

props 唯一能改變的條件取決於父級,所以當父級 component 改變時,子元件可以 call componentWillReceiveProps 來監看變化或是塞給 state


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK