reactjs - 如何在处理函数中链接 useLazyQuery 钩子
问题描述
我想在处理函数中链接 apollo useMutation 和 useQuery 钩子。我似乎无法将 useLazyQuery 挂钩的数据属性设置为别名 - 或者就此而言,突变属性加载、错误、数据。我可以使用 useMemo 获得相同的效果,但我想探索如何使用承诺链中的惰性查询。
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [requestLogin, { loading, error }] = useMutation(LOGIN_USER)
const [getUserProfile, {
loading: loadingProfile,
error: errorProfile,
data: profileData
}] = useLazyQuery(GET_USER_PROFILE)
const submitHandler = (event) => {
event.preventDefault()
requestLogin({
variables: {
email: email,
password: password
}
}).then(({ data }) => {
console.log("INITIAL DATA", data)
login(data.login.token, data.login.user)
}).then(({ data, profileData }) => getUserProfile({
variables: {
account_id: data.login.user.account.id
}
})).then(profileData => {
console.log("DATA", profileData)
history.push('/')
})
}
解决方案
推荐阅读
- wordpress - 如何在另一个简码中添加高级自定义字段变量
- aws-lambda - 为什么我们应该在 VPC 中放置一个与外部服务对话的 Lambda?
- google-cloud-platform - 综合指数未编制索引
- python - 如何使用 python 更新 gettext 模块中的 .po 和 .pot 文件
- vue.js - 如何在多个组件上使用多个查询参数来创建动态 URL
- android - Blogger api 总是返回 401 错误响应
- javascript - JS 继承复习 - ES6+
- javascript - 在 MicrosoftAjax.js 中获取 pageLoad 错误
- angular - 检查浏览器中是否有firebase消息传递
- java - 如何使用 Java Streams 从对象列表中获取 Set