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

import React from "react";
import { render } from "react-dom";
import ApolloClient, { gql } from "apollo-boost";
import { ApolloProvider, Query } from "react-apollo"; const client = new ApolloClient({ uri: "https://graphql-pokemon.now.sh" }); const GET_POKEMON = gql`
query($name: String!) {
pokemon(name: $name) {
name
image
}
}
`; const Pokemon = ({ name, image }) => {
return (
<div>
<div>{name}</div>
<img src={image} />
</div>
);
}; const PokemonQuery = () => (
<Query query={GET_POKEMON} variables={{ name: "pikachu" }}>
{({ loading, error, data }) => {
if (loading) return <div>Loading...</div>;
if (error) return <div>Error</div>;
return <Pokemon name={data.pokemon.name} image={data.pokemon.image} />;
}}
</Query>
); const ApolloApp = () => (
<ApolloProvider client={client}>
<PokemonQuery />
</ApolloProvider>
); 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. Java缓存server调优

    搜索降级方案中xmn開始使用bizer默认的128M,很慢. 偶然改成1G,效果立刻上来,可是xmx调大并没有明显效果.                  100并发             200并 ...

  2. jstl 标签 循环 序号

     大家好: 今天搜了一天.最终找到它了,尽管不是我想要的,可是为了我辛苦的一天.我也要记录下: <c:forEach items="${signBusList}" var ...

  3. 自己定义隐式转换和显式转换c#简单样例

    自己定义隐式转换和显式转换c#简单样例 (出自朱朱家园http://blog.csdn.net/zhgl7688) 样例:对用户user中,usernamefirst name和last name进行 ...

  4. Linux内核OOM机制的详细分析【转】

    本文转载自:http://blog.csdn.net/liukuan73/article/details/43238623 Linux内核根据应用程序的要求分配内存,通常来说应用程序分配了内存但是并没 ...

  5. 【转】坑爹的AsyncTask之根本停不下来

    原文网址:http://www.jianshu.com/p/0c6f4b6ed558 上篇<坑爹的AsyncTask之内存泄露>已经简单的探讨过线程使用不当会造成内存泄露的问题,在Acti ...

  6. Xposed那些事儿 — xposed框架的检测和反制

    之前看到有人发了关于使用xposed屏蔽抖音检测xposed的思路(https://www.52pojie.cn/thread-684757-1-1.html),贴出了部分伪代码,但觉抖音写的蛮有意思 ...

  7. guice整合struts2与jpa,guice的使用(九)

    传统我们开发一般使用ssh,但是有些微服务应用的项目我们不需要这么臃肿的框架做开发,于是采用了guice+struts2+guice作为框架组合进行了开发. 先看我们项目引用的jar包: 使用的时候一 ...

  8. Svn install and use

    1.安装服务 使用yum安装subversion,简单.不繁琐. 1 yum install -y subversion 2.创建版本库 1 2       mkidr /svn/obj        ...

  9. 完美解决ios10及以上Safari无法禁止缩放的问题

    移动端web缩放有两种: 1.双击缩放: 2.双指手势缩放. 在iOS 10以前,iOS和Android都可以通过一行meta标签来禁止页面缩放 <meta content="widt ...

  10. C# 4.0新加特性

    协变和逆变 这个在C#2.0中就已经支持委托的协变和逆变了,C#4.0开始支持针对泛型接口的协变和逆变: IList<string> strings = new List<strin ...