为了账号安全,请及时绑定邮箱和手机立即绑定

react - ts中,render内不允许匿名函数,如果不使用匿名函数,则提示不允许更新state

react - ts中,render内不允许匿名函数,如果不使用匿名函数,则提示不允许更新state

慕村9548890 2019-01-31 21:02:50
const renderItem = (item: string, index: number) => {  console.log(warpProps.handleItemDelete)  return (    <List.Item>       <p onClick={warpProps.handleItemDelete(index)}>{item}</p>     </List.Item>   ) }报错Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.如果是匿名函数const renderItem = (item: string, index: number) => {  console.log(warpProps.handleItemDelete)  return (    <List.Item>       <p onClick={() => warpProps.handleItemDelete(index)}>{item}</p>     </List.Item>   ) }报错
查看完整描述

1 回答

?
红颜莎娜

TA贡献1842条经验 获得超12个赞

报错是tslint报错,我把匿名函数限制关了就好了

查看完整回答
反对 回复 2019-01-31
  • 1 回答
  • 0 关注
  • 500 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信