本文介绍了等待useLazyQuery响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在按下提交按钮时调用查询,然后处理响应。
我需要这样的东西:
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 }提前谢谢!
推荐答案毕竟,这就是我的解决方案。
export function useLazyQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode) { const client = useApolloClient() return React.useCallback( (variables: TVariables) => client.query<TData, TVariables>({ query: query, variables: variables, }), [client] ) }更多推荐
等待useLazyQuery响应
发布评论