最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

千鋒教育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)完整版的評論 (共 條)

分享到微博請遵守國家法律
涡阳县| 青神县| 忻城县| 平原县| 安塞县| 谢通门县| 买车| 英吉沙县| 连山| 江孜县| 蒲江县| 麻城市| 墨玉县| 安龙县| 日照市| 库伦旗| 墨脱县| 新宁县| 东港市| 武功县| 武强县| 新龙县| 新建县| 井陉县| 鹤庆县| 休宁县| 通江县| 阿拉尔市| 连州市| 集安市| 易门县| 衡南县| 定安县| 渝中区| 周口市| 花莲市| 嘉义县| 灌云县| 龙游县| 平果县| 沁阳市|