gpt4 book ai didi

reactjs - 等待 useLazyQuery 响应

转载 作者:行者123 更新时间:2023-12-03 19:11:11 26 4
gpt4 key购买 nike

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

我需要这样的东西:

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

尝试 #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
}

提前致谢!

最佳答案

这对我有用:

const { refetch } = useQuery(CHECK_EMAIL, {
skip: !values.email
})

const handleSubmit = async () => {
const res = await refetch({ variables: { email: values.email }})
console.log(res)
}

关于reactjs - 等待 useLazyQuery 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62122523/

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