gpt4 book ai didi

javascript - React Native 问题 : [Unhandled promise rejection: TypeError: f is not a function.(在 'f()' 中, 'f' 未定义)]

转载 作者:行者123 更新时间:2023-12-05 01:32:05 26 4
gpt4 key购买 nike

我正在尝试使用状态和获取创建一个登录系统,以便用户可以接收他的有效 token ,然后将其放入异步存储的存储中。我还处于与API(expressjs)通信的阶段。当我输入电子邮件和密码时一切正常,我确实收到了 json 中的 token ,但我有一个警告类型错误告诉我:

[Unhandled promise rejection: TypeError: f is not a function. (In 'f()', 'f' is undefined)]

目前我的代码非常简单(我完全不知道它来自哪里):

const onSubmit = () => {
setLoading(true)
fetch('http://192.168.1.36:3000/api/users/login', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
password: password
})
})
.then((response) => response.json())
.then((res) => console.log(res))
.catch((err) => console.log(err))
.finally(setLoading(false));
}

我不知道我在 fetch 中使用的语法对于登录系统来说是否“好”和“优化”,但我希望我的解释足够清楚。

坦克

最佳答案

认为这与您的 finally 子句有关:

.finally(setLoading(false));

finally 函数必须传递一个函数本身。两种方法:

.finally(() => setLoading(false));
.finally(setLoading.bind(undefined, false));

关于javascript - React Native 问题 : [Unhandled promise rejection: TypeError: f is not a function.(在 'f()' 中, 'f' 未定义)],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65766025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com