国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

千鋒教育2022版React全家桶教程_react零基礎入門到項目實戰(zhàn)完整版

2023-07-15 15:31 作者:bili_93106963981  | 我要投稿

使用hooks的理由

1、高階組件為了復用,導致代碼層級復雜

2、生命周期復雜

3、寫成functional組件,無狀態(tài)組件,因為需要狀態(tài),又改成class,成本高


useState


引用useState

import React, { useState } from 'react'

創(chuàng)建

const [text, settext] = useState('馬達啦')

input框獲取添加到數組展示

<input style={{ marginTop: 30 }} onChange={(e) => hiderinp(e)} value={text} />

hiderinp事件修改settext值

?const hiderinp = (e) => {

? ? ? ? settext(e.target.value)

? ? }

先創(chuàng)建數組

const [list, setlist] = useState(['哈希喇嘛'])

添加到數組中

<button onClick={hiderbtn}>獲取input值加到list中</button>

const hiderbtn = () => {

? ? ? ? console.log(text);

? ? ? ? setlist([...list, text])

? ? ? ? settext('')

? ? }

刪除數組

<button onClick={() => del(index)}>刪除</button>

const del = (index) => {

? ? ? ? let arr = list

? ? ? ? arr.splice(index, 1)

? ? ? ? setlist([...arr])

? ? }

有數組就不顯示,沒有就展示

<div style={{display:list.length?'none':'block'}}>暫無數據</div>


千鋒教育2022版React全家桶教程_react零基礎入門到項目實戰(zhàn)完整版的評論 (共 條)

分享到微博請遵守國家法律
汪清县| 古交市| 邵东县| 枣阳市| 夹江县| 微博| 绥中县| 栖霞市| 西和县| 奉贤区| 沅江市| 汾西县| 文成县| 永州市| 同仁县| 旅游| 新晃| 赞皇县| 阿尔山市| 怀宁县| 利辛县| 柞水县| 贺兰县| 喀什市| 裕民县| 定边县| 渭南市| 江安县| 金川县| 会理县| 普宁市| 邹城市| 永顺县| 唐河县| 周宁县| 宜兴市| 客服| 博客| 本溪市| 八宿县| 古田县|