javascript - 为什么我的 setstate 给我未定义?反应
问题描述
我有这个 useState 声明:
const [userLogged, setUserLogged] = useState();
这是我在自定义钩子中的代码片段:
await axios.post('http://localhost:3000/users/register', form).then( (res)=> {
setUserLogged(res.config.data)
console.log(UserLogged)
window.location.href = "http://localhost:3001/"
});
当我的回调工作时,我想从 res设置userLogged
使用用户对象的状态,但它不起作用。如果一个状态,我得到一个。setUserLogged
console.log
userLogged
undefined
我尝试通过将布尔值或字符串传递给setUserLogged
进行测试,但它也未定义。
解决方案
推荐阅读
- windows - Samba 共享默认为来宾访问
- python - 如何使用python仅打印child.tag并删除xml中的pretext
- php - 获取变量内容和剥离变量以仅返回数字的函数
- wordpress - 无法导入使用 Vue WordPress Starter 构建的主题
- python - 将 Excel 中的 =LARGE 和 =SMALL 函数复制到 Python
- airflow - 在从 BashOperator 调用的 python 文件中使用 xcom_push 和 xcom_pull
- mahapps.metro - 如何在 Orchestra Shell MahApps 中排除 InfoBarMessageControl?
- ms-access - Microsoft Access 中有没有一种方法可以从具有复合主键的 Excel 文件中导入?
- jsf-2 - 如何使用 ui:param 将后端 bean 对象传递给包含页面后端 bean
- ios - 无法安装此应用程序,因为无法验证其完整性。FireBase ios