date: 2021/7/26
⚛️ React - 函數式組件
React 起手式
-
老規矩,先建立一個 HTML,並搭建好環境
還不知道起手式請點我
創建函數式組件
-
在 script 中,創建函數式組件
-
畫面呈現
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
打開開發人員工具的 Components 頁面可以看到組件、屬性與版本
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
執行組件後 React 做了什麼?
- React 解析組件標籤,找到了 Demo 組件。
- 發現組件是使用函數定義的,隨後調用該函數,將返回的虛擬 DOM 轉為真實 DOM,隨後呈現在頁面中。
函數式組件 3 大重點須知
- 組件首字母必須大寫
- 必須要 return 返回值
- 讓 ReactDOM 渲染必須使用閉合標籤
參考資料