分享一些踩過的坑
react中使用map時onClick事件失效
<span>
{
count.map(
(item,index)=>{
return <span style={{paddingRight:2,cursor:'pointer'}} key={index} onClick={handleEditCount(item[1],item[2])}>{item[0]}<Icon type="edit" /></span>
}
)
}
</span>
這樣是真的失效嗎
不,只是不會用而已
其實把函數改成箭頭函數就能用啦
<span>
{
count.map(
(item,index)=>{
return <span style={{paddingRight:2,cursor:'pointer'}} key={index} onClick={() => handleEditCount(item[1],item[2])}>{item[0]}<Icon type="edit" /></span>
}
)
}
</span>
順便說一下 .bind相當於箭頭函數
