6.3节 添加componentDidMount后,console里报warning
来源:6-3 Redux 中发送异步请求获取数据
			慕设计63794
2021-02-25
6.3节,跟着老师做了一遍,功能没问题,但console里报如下warning,去掉componentDidMount后,warning消失:
index.js:1 Warning: Can’t call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to this.state directly or define a state = {}; class property with the desired state in the TodoList component.
我的componentDidMount是这么写的,在TodoList.js中
componentDidMount() {
axios.get("/list.json").then((res)=>{
const data = res.data;
const action = getInitListAction(data);
store.dispatch(action) // 如果注释掉这行,warning也会消失
})
}
写回答
	2回答
- 
				
						慕设计63794
提问者
2021-02-25
见下图:
012021-02-28 - 
				
						Dell
2021-02-25
截图给我个警告的图看一下
012021-02-25 
相似问题
