【发布时间】:2021-08-15 03:02:43
【问题描述】:
所以我使用了 material-UI 中的模态组件,并使用“打开”状态挂钩来控制其可见性。在这个组件中,我创建了一个登录页面组件,它将使用 Axios 发布信息并将打开状态设置为 false,从而关闭模式。我点击登录按钮后,控制台报告
无法对未安装的组件执行 React 状态更新。
这是我的代码:
function handleSubmit(e){
e.preventDefault();
AxiosInstance
.post("/api/token/", account)
.then((res)=>{
localStorage.setItem('access_token', res.data.access);
localStorage.setItem('refresh_token', res.data.refresh);
AxiosInstance.defaults.headers['Authorization'] = 'Bearer '+localStorage.getItem('access_token');
console.log(res);
props.setOpen(false);
})
.catch((error)=>{
})
}
【问题讨论】:
标签: reactjs axios material-ui