小编Jul*_*cas的帖子

等待 useLazyQuery 响应

我需要在按下提交按钮时调用查询,然后处理响应。

我需要这样的东西:

const [checkEmail] = useLazyQuery(CHECK_EMAIL)
const handleSubmit = async () => {
  const res = await checkEmail({ variables: { email: values.email }})
  console.log(res) // handle response
}
Run Code Online (Sandbox Code Playgroud)

尝试 #1:

const [checkEmail, { data }] = useLazyQuery(CHECK_EMAIL)
const handleSubmit = async () => {
  const res = await checkEmail({ variables: { email: values.email }})
  console.log(data) // undefined the first time
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

reactjs graphql apollo-client

6
推荐指数
3
解决办法
5756
查看次数

标签 统计

apollo-client ×1

graphql ×1

reactjs ×1