標籤:

react 爭取每天看一點 二

Components and Props

components是獨立的ui片段

但是我個人認為這個概練一定是來自於php模板引擎

實際上這種技術無法重複利用

莫名其妙的不區分標籤問題

For example, <div />represents an HTML div tag, but <Welcome /> represents a component and requires Welcometo be in scope.

react認為自己的標籤大寫 就可以和原生標籤做區分了嗎 這不扯淡嗎

函數式不是說說的

react希望拆分組件到最小不可分割地步

Props are Read-Only

react的props不是elements的props 應該來說就是傳參

All React components must act like pure functions with respect to their props.

必須是純凈的函數

這些東西很多人可能不理解 這就是php模板引擎的渲染啊

State and Lifecycle

react本質上就是通過對於有限區域動態調用函數再渲染

納悶問題就來了

如果這個函數里調用了其他函數呢

react不會自己自動刷新

需要手動call apply

不要去修改state某個屬性自身

this.setState((prevState, props) => ({ counter: prevState.counter + props.increment}));

Handling Events

<button onClick={activateLasers}> Activate Lasers</button>

注意 react 的事件並非返回標準事件

Here, e is a synthetic event. React defines these synthetic events according to the W3C spec, so you don』t need to worry about cross-browser compatibility. See the SyntheticEventreference guide to learn more.

這裡我突然意識到

小程序沒有提供prevState哎

<button onClick={(e) => this.deleteRow(id, e)}>Delete Row</button>

嗯我發現了這種寫法

推薦閱讀:

段子雜糅

TAG:廢話 |