React 根據官方總結的規範

2021-09-07 04:50:03 字數 909 閱讀 5291

1、語法上,根據生命週期方法執行的順序編寫**

(1 生命週期方法[getdefaultprops,getinitialstate,componentwillmount,componentdidmount,componentwillreceiveprops,shouldcomponentupdate,componentwillupdate,componentdidupdate,componentwillunmount]

具體的生命週期詳解見:

(2 其他的私有方法

(3 render()方法

2、事件處理函式的命名: 「handle+eventname」

<

component

onclick

= onlaunchmissiles

= />

3、元件驗證

react 元件 都應該完成proptypes驗證。每乙個this.props的屬性都應該有乙個與之對應的proptypes

避免使用這些沒有描述意義的 prop-types:

最好使用:

4、能用props就不要用state,這一定程度上可以減少應用程式的複雜度

5、盡量少用jquery去操作dom(有必要的話,把jquery外掛程式包裝在react元件中)

6、盡量不用例如backbone的模型,可以直接使用flux action,或者$.ajax來代替。

總結的編碼規範

1 巨集定義格式 每個單詞用下劃線隔開。示例 define yyy 20 define yyy 20 各用兩個 tab隔開 2 一律不得出現常量,對於出現的常量 指數字和字串 用意義明顯的巨集定義 或列舉變數 代替。3 每個函式體不能過長,原則上不超過 200行 4 每個檔案不能過長,原則上不超過 ...

react總結 style的寫法

本篇文章複習在react中style的4種寫法 1.內聯式 不推薦 import react,from react class style extends react.component render return export default style 這種寫法不推薦使用,樣式多了之後,會導致 ...

學習官方SSIS教程的錯誤總結

其他待根據學習進度更新 學習位址 錯誤原因是因為跟著文章把properties的locateid設定為了english 查詢後發現實際上應該設定為chinese.教程文章中的sql語句為 select from sales currency where currencycode in ars aud...