第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

React Item.map 不是函數(shù)

React Item.map 不是函數(shù)

開心每一天1111 2023-05-19 19:56:07
我正在嘗試為狀態(tài)數(shù)組 personState 中的值實(shí)現(xiàn)名稱更改處理程序。const [personState, setPersonState] = useState([            { id:'asdasd', name: "Max", age: 28 },            { id:'asdasdsd', name: "Manu", age: 29 },            { id:'assddasd', name: "Stan", age: 31 },  ]);這是處理名稱更改事件的函數(shù):const nameChangeHandler = (event, id) => {        const personIndex = personState.findIndex(p => {            return p.id === id;//find index of the value in personstate with id equal id passed in        })        const person = {...personState[personIndex]} // get all the object value inside that person        person.name = event.target.value; //change name of that copy person to the input value        const persons = [...personState]; //copy array of current personState        persons[personIndex] = person// change value of that person in the array        setPersonState(...personState, persons);//set state with the new array    }下面是我在切換顯示時(shí)使用 map 遍歷 personState 數(shù)組的地方。用于顯示數(shù)據(jù)和刪除數(shù)據(jù)的映射工作但是當(dāng)我想實(shí)現(xiàn)名稱更改時(shí),它突然返回:TypeError: personState.map is not a functionAppD:/React App/react-guide/src/App.js:52  49 |  <button onClick={() => togglePersonHandler()}>  50 |      Switch Name  51 |  </button>> 52 |  {showPerson ? personState.map((person,index) => {  53 |       return <Person click = {()=>deletePersonHandler(index)} changed={(event) => nameChangeHandler(event, person.id)} key={person.id} name={person.name} age ={person.age}/>  54 |     }) : null}  55 | </div>任何幫助將非常感激
查看完整描述

1 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊

這是罪魁禍?zhǔn)祝?/p>

setPersonState(...personState, persons);//set state with the new array

它應(yīng)該被新值替換(只有一個(gè)參數(shù))

setPersonState(persons);//set state with the new array


查看完整回答
反對(duì) 回復(fù) 2023-05-19
  • 1 回答
  • 0 關(guān)注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)