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. 0x53 区间DP

    石子合并 搞笑 #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib& ...

  2. Windows下Vim主题变更

    默认的好丑! 主题位置. 修改配置文件. 添加主题设置. 新的主题,很高端大气. set fileencodings=utf8,ucs-bom,cp936,big set fileencoding=u ...

  3. JS轮播图动态渲染四种方法

    一. 获取轮播图数据  ajax 二.根据数据动态渲染 (根据当前设备 屏幕宽度判断) 1. 准备数据 2. 把数据转换成html格式的字符串 动态创建元素 字符串拼接 模板引擎 框架方法 2.把字符 ...

  4. npm run dev 出现警告

    WARNING in ./node_modules/_webpack@3.10.0@webpack/buildin/global.js There are multiple modules with ...

  5. redis实现计数--------Redis increment

    经理提出新的需求,需要知道每天微信推送了多少条模板消息,成功多少条,失败多少条,想到用Redis缓存,网上查了一些资料,Redis中有方法increment,测试代码如下 Controller imp ...

  6. pythonOCC版 瓶子代码

    #!/usr/bin/env python # -*- coding:utf-8 -*- ##Copyright 2009-2015 Thomas Paviot (tpaviot@gmail.com) ...

  7. 将实体类/匿名对象转换为SqlParameter列表

    每次操作数据库参数化实在是太麻烦了,于是自己瞎琢磨,琢磨出下面扩展方式,能力有限,还有不足之处,请多多指教. /// <summary> /// <remarks> /// & ...

  8. vue-router 原理解析

    “更新视图但不重新请求页面”是前端路由原理的核心之一,

  9. Codeforces Round #448

    Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...

  10. JS排序之冒泡排序

    冒泡排序的两种策略: <script>// 第一种思路:// 一个数组中的数据,拿第一个和剩下的依次进行对比,数值小的赋值给第一个,一轮比较过后,则数值小的放在最前边.// 第二轮比较,则 ...