控制台警告的提示该怎么解决呢 reactjs

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the GroupManag component.

阅读 3.1k
2 个回答

组件没有渲染之前,直接通过 this.state = {}去赋值就好。

楼上的方法不是很赞同,这问题出现的原因是你的组件卸载了,但是setState确执行了。正确做法是在卸载组件的时候:this.setState(() => {})

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题