博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React + GraphQL] Use useLazyQuery to manually execute a query with Apollo React Hooks
阅读量:4983 次
发布时间:2019-06-12

本文共 1171 字,大约阅读时间需要 3 分钟。

When using useQuery from Apollo React Hooks, the request will be sent automatically after the component has been mounted. This might not be the desired behaviour as we might want to send the request in response to user action (for instance, after a button click).

In this lesson we're going to learn how to use useLazyQuery hook to execute a query manually in order to fetch dog pictures.

 

import React, { Fragment, useState } from "react";import { gql } from "apollo-boost";import { useLazyQuery } from "@apollo/react-hooks";const GET_DOGGO = gql`  query Dog($breed: String!) {    dog(breed: $breed) {      id      displayImage    }  }`;const App = () => {  const [breed, setBreed] = useState("dingo");  const [getDog, { loading, data }] = useLazyQuery(GET_DOGGO);  if (loading) {    return 

Loading...

; } return (
{data && data.dog ? (
Cute Doggo ) : null}
setBreed(event.target.value)} placeholder="Choose breed" />
);};export default App;

 

转载于:https://www.cnblogs.com/Answer1215/p/11431567.html

你可能感兴趣的文章
seq命令
查看>>
centos7常见的操作01 UTC CST
查看>>
Java必会的基础知识(2)
查看>>
NHibernate系列文章目录
查看>>
函数内置方法
查看>>
Python_58之logging模块
查看>>
正则表达式
查看>>
楼房重建(分块优化)
查看>>
斐波那契数列(矩阵加速递推)
查看>>
HTTP笔记之一
查看>>
Gradle 学习一
查看>>
hiho #1223 不等式
查看>>
EOS多节点同步代码分析
查看>>
Synchronized关键字
查看>>
webfont 字体
查看>>
lua快速入门
查看>>
FullCalendar 官方文档翻译
查看>>
plsql 操纵表数据的2种方式
查看>>
输出日期
查看>>
hibernate中实体与数据库中属性对应的类型
查看>>