In this lesson I refactor a React component that utilizes the graphql higher-order component to the new Query render prop component baked into react-apollo.

Additional Resources: What's next for React Apollo

  1. import React from "react";
  2. import { render } from "react-dom";
  3. import ApolloClient, { gql } from "apollo-boost";
  4. import { ApolloProvider, Query } from "react-apollo";
  5.  
  6. const client = new ApolloClient({ uri: "https://graphql-pokemon.now.sh" });
  7.  
  8. const GET_POKEMON = gql`
  9. query($name: String!) {
  10. pokemon(name: $name) {
  11. name
  12. image
  13. }
  14. }
  15. `;
  16.  
  17. const Pokemon = ({ name, image }) => {
  18. return (
  19. <div>
  20. <div>{name}</div>
  21. <img src={image} />
  22. </div>
  23. );
  24. };
  25.  
  26. const PokemonQuery = () => (
  27. <Query query={GET_POKEMON} variables={{ name: "pikachu" }}>
  28. {({ loading, error, data }) => {
  29. if (loading) return <div>Loading...</div>;
  30. if (error) return <div>Error</div>;
  31. return <Pokemon name={data.pokemon.name} image={data.pokemon.image} />;
  32. }}
  33. </Query>
  34. );
  35.  
  36. const ApolloApp = () => (
  37. <ApolloProvider client={client}>
  38. <PokemonQuery />
  39. </ApolloProvider>
  40. );
  41.  
  42. render(<ApolloApp />, document.getElementById("root"));

[GraphQL] Apollo React Query Component的更多相关文章

  1. [GraphQL] Apollo React Mutation Component

    In this lesson I refactor a React component that utilizes a higher-order component for mutations to ...

  2. [React + GraphQL] Use useLazyQuery to manually execute a query with Apollo React Hooks

    When using useQuery from Apollo React Hooks, the request will be sent automatically after the compon ...

  3. GraphQL + React Apollo + React Hook + Express + Mongodb 大型前后端分离项目实战之后端(19 个视频)

    GraphQL + React Apollo + React Hook + Express + Mongodb 大型前后端分离项目实战之后端(19 个视频) GraphQL + React Apoll ...

  4. GraphQL + React Apollo + React Hook 大型项目实战(32 个视频)

    GraphQL + React Apollo + React Hook 大型项目实战(32 个视频) GraphQL + React Apollo + React Hook 大型项目实战 #1 介绍「 ...

  5. React & styled component

    React & styled component https://www.styled-components.com/#your-first-styled-component tagged t ...

  6. GraphQL & Apollo & Vue

    GraphQL & Apollo & Vue https://www.howtographql.com/vue-apollo/0-introduction/ https://githu ...

  7. React Query & SWR

    React Query & SWR HTTP request all in one solution React Query Hooks for fetching, caching and u ...

  8. react slot component with args

    react slot component with args how to pass args to react props child component https://codesandbox.i ...

  9. react hooks & component will unmount & useEffect & clear up

    react hooks & component will unmount & useEffect & clear up useEffect & return === u ...

随机推荐

  1. ACdream 1154 Lowbit Sum (数位DP)

    Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...

  2. 为了世界的和平~一起上caioj~~~!

    打Call~打Call~打Call~~~!!! 世界毁灭了你在哪???不要犹豫,快去caioj!!! 无比优质的oj,未来大牛的明智之选----就是caioj~~~

  3. Linux - 网络相关指令

    系统时间与开关机 查看系统时间 date 查看硬件日期 hwclock 学习Linux不必全部指令都会,只要记住主要常用的几个就可以了.--MK 关机命令 shutdown init reboot p ...

  4. [xPlugin] smartupload jsp图片上传

    URL:http://www.cnblogs.com/ISeeYouBlogs/p/jsp.html 1.要实现图片上传,首先需要一个组件,这里我用的是smartupload.jar可以到这里下载ht ...

  5. 【优化算法】遗传算法GA求解混合流水车间调度问题(附C++代码)

    00 前言 各位读者大家好,好久没有介绍算法的推文了,感觉愧对了读者们热爱学习的心灵.于是,今天我们带来了一个神奇的优化算法--遗传算法! 它的优点包括但不限于: 遗传算法对所求解的优化问题没有太多的 ...

  6. Kaggle爆文:一个框架解决几乎所有机器学习问题

      上周一个叫 Abhishek Thakur 的数据科学家,在他的 Linkedin 发表了一篇文章 Approaching (Almost) Any Machine Learning Proble ...

  7. .net几种文件下载的方法

    .Net文件下载方式.... 之前在写上传文件.下载文件的时候,发现Response对象里面有好几种下载文件的方式,之后自己亲自实践了这几种方法,记录下以便以后复习... WriteFile文件下载 ...

  8. 第二次作业&熟悉使用工具

     GIT地址  我的地址  GIT用户名  995020892w  学号后五位  81105  博客地址  我的博客  作业链接  第二次作业 一.环境配置过程 安装vs2017 因为以前学习C#相关 ...

  9. sql多表关联

    inner join(等值连接) 只返回两个表中联结字段相等的行 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有 ...

  10. 01--数据结构——动态链表(C++)

    数据结构——动态链表(C++)   定义一个节点: [cpp] view plain copy   print? #include <iostream> using namespace s ...