react入門 筆記 自定義元件

2021-10-01 11:32:45 字數 747 閱讀 4428

方式1:工廠函式元件(簡單元件)

"text/babel"

>

// 1.定義元件

// 方式1:工廠函式元件(簡單元件)

function

mycomponent()

// 2.渲染元件標籤

reactdom.

render

(>

, document.

getelementbyid

('example1'))

<

/script>

方式2:es6類元件(複雜元件)
class

mycomponent2

extends

react.component

理解:

state 是元件物件最重要的屬性,值是物件(可以包含多個資料)

元件被稱為"狀態機",通過更新元件的state來更新對應的頁面顯

示(重新渲染元件)

操作:初始化狀態

constructor

(props)

}

2)讀取某個狀態值

this

.state.statepropertyname

3)更新狀態—>元件介面更新

this

.setstate

(

自定義React元件

如果還沒有專案,請看建立umi專案 訪問http localhost 8000實際由src pages index.js渲染,內容為 export default function 使用antd新增乙個輸入框和乙個按鈕 import from antd export default function...

react 自定義日曆元件

基於hooks開發的自定義日曆元件,可以根據自己需要修改 params searchbar 搜尋引數 列表資料 description 修改請備註 location grey const main props 獲取當前年份 const getfullyear date date number con...

react demo3 自定義react元件

react dome 3 建立乙個元件類 需求 渲染一行標題,顯示 hello,world lang en charset utf 8 react dometitle src build react.js script src build react dom.js script src build ...