【发布时间】:2021-04-09 07:24:11
【问题描述】:
如果我采取行动 onPress={() => kakaoLosing()
我想通过使用异步等待从 getProfile 获取数据(这是配置文件)
在将数据发送到 KAKAOLOG_IN_REQUEST 之后,
这是我的代码
import {
getProfile as getKakaoProfile,
} from '@react-native-seoul/kakao-login';
const Vieww = ({}) => {
const kakaoLosing = useCallback(() => {
const getProfile = async () => {
const profile = await getKakaoProfile();
};
dispatch({
type:KAKAOLOG_IN_REQUEST,
data:profile
})
},[]);
return (
<Button1 onPress={() => kakaoLosing()} >
<Label>
profile
</Label>
</Button1>
但如果我使用此代码
发生了这个错误
ReferenceError: Can't find variable: profile
如何修复我的代码??
【问题讨论】:
-
你为什么使用 useCallback 代替普通的箭头函数?有什么目的吗?
-
您已经在
getProfile函数范围内关闭了profile,它在useCallback挂钩回调中不可用。然后你也不要打电话给getProfile来提出请求。 -
我在您的回调中没有看到
async关键字 -
请看看我的回答,也许它会帮助你:)
标签: javascript node.js reactjs react-native