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. Jenkins project

    1.project name 这个作为git clone的target folder 2.Multiple SCMs 建立2个git类型的操作,相互独立. additional Behaviors 设 ...

  2. DNS 隐蔽通道工具资料汇总

    http://www.cnblogs.com/bonelee/p/7651746.html DNS隧道和工具 内含dns2tcp.iodine.dnscat2工具的简单使用说明 iodine工具的使用 ...

  3. DDos攻击,使用深度学习中 栈式自编码的算法

    转自:http://www.airghc.top/2016/11/10/Dection-DDos/ 最近研究了一篇论文,关于检测DDos攻击,使用了深度学习中 栈式自编码的算法,现在简要介绍一下内容论 ...

  4. Node.js:REPL(交互式解释器)

    ylbtech-Node.js:REPL(交互式解释器) 1.返回顶部 1. Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器 ...

  5. javascript一个作用域案例分析

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. lz的第一个RN项目

    这是lz 成功在原有项目上集成的第一个ReactNative 项目. 参考官方网址: http://reactnative.cn/docs/0.43/integration-with-existing ...

  7. Oracle PL/SQL开发基础(第三十四弹:RAISE_APPLICATION_ERROR)

    RAISE_APPLICATION_ERROR在子程序内部使用时,能从存储子程序中抛出自定义的错误消息.这样就能将错误报告给应用程序而避免范围未捕获异常. 语法如下: RAISE_APPLICATIO ...

  8. Kinect安装与配置(openNI2)

    原文链接:http://blog.csdn.net/chenxin_130/article/details/8580636 简介 最近OpenNI2的推出,小斤也要多给博客除除草了,并在闲暇之余做一些 ...

  9. php进程控制

    1 POSIX扩展    posix_access($file,$mode)  查看文件的访问权限,可以由is_readable等几个函数代替    posix_errno()  返回posix函数执 ...

  10. 洛谷P1563 玩具谜题 简单模拟

    没意义,注意方向别判错. Code: #include<cstdio> #include<cstring> using namespace std; const int max ...