[GraphQL] Apollo React Query Component
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的更多相关文章
- [GraphQL] Apollo React Mutation Component
In this lesson I refactor a React component that utilizes a higher-order component for mutations to ...
- [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 ...
- GraphQL + React Apollo + React Hook + Express + Mongodb 大型前后端分离项目实战之后端(19 个视频)
GraphQL + React Apollo + React Hook + Express + Mongodb 大型前后端分离项目实战之后端(19 个视频) GraphQL + React Apoll ...
- GraphQL + React Apollo + React Hook 大型项目实战(32 个视频)
GraphQL + React Apollo + React Hook 大型项目实战(32 个视频) GraphQL + React Apollo + React Hook 大型项目实战 #1 介绍「 ...
- React & styled component
React & styled component https://www.styled-components.com/#your-first-styled-component tagged t ...
- GraphQL & Apollo & Vue
GraphQL & Apollo & Vue https://www.howtographql.com/vue-apollo/0-introduction/ https://githu ...
- React Query & SWR
React Query & SWR HTTP request all in one solution React Query Hooks for fetching, caching and u ...
- react slot component with args
react slot component with args how to pass args to react props child component https://codesandbox.i ...
- react hooks & component will unmount & useEffect & clear up
react hooks & component will unmount & useEffect & clear up useEffect & return === u ...
随机推荐
- Softmax回归——logistic回归模型在多分类问题上的推广
Softmax回归 Contents [hide] 1 简介 2 代价函数 3 Softmax回归模型参数化的特点 4 权重衰减 5 Softmax回归与Logistic 回归的关系 6 Softma ...
- k8s Job、Cronjob 的使用
Job负责处理任务,即仅执行一次的任务,它保证批处理任务的一个或多个Pod成功结束.而CronJob则就是在Job上加上了时间调度. Job 我们用Job这个资源对象来创建一个任务,我们定一个Job来 ...
- [ASPX] DotLiquid-Asp.net模板引擎
以前用过一段时间的PHP,感觉非常不错,其中最让我难忘的就是Smarty模板引擎,当时就微微地想Asp.net里有没有像这样的模板引擎呢?不过由于之后的工作内容都用不到,或者说没有想到用模板,这想法也 ...
- SwiftUI 官方教程(四)
SwiftUI 官方教程(四) 4. 自定义 Image View 搞定名称和位置 view 后,我们来给地标添加图片. 这不需要添加很多代码,只需要创建一个自定义 view,然后给图片加上遮罩.边框 ...
- Java中利用随机数的猜拳游戏
Java中利用随机数的猜拳游戏,实现非常简单,重难点在于随机数的产生. 首先GameJude类是用于判断输赢的一个类: package testGame; public class GameJudge ...
- AndroidStudio项目CMakeLists解析
# For more information about using CMake with Android Studio, read the# documentation: https://d.and ...
- 第4章 部署模式 Deployment Plan(部署规划)
已开发了基于组件的应用程序,该应用程序在逻辑上构造为多层结构,如 Three-Layered Services Application. 中所述.您希望将它分布到一组在物理上为多级结构的服务器上,如 ...
- 在无任何报错的情况下 pagehelper.startpage分页无效问题
问题原因:自从spring boot开始使用2.0x版本以上后,很多相应的依赖文件版本开始变化 该版本为spring-boot 1.4.1 <dependency> <groupId ...
- R 连接DB2数据库,并制作词图
#写在前面的话:此教程主要是用R连接了DB2数据库,并进行文本分析,制作了词图 #教程为markdown编写 ---title: "网站留言分析"output: html_docu ...
- 关于VS 2013连接Microsoft Access 2013的相关问题
① 下载安装Microsoft Access Database Engine 2010 Redistributable(28MB),共有32bit(下载)和64bit(下载)两个版本,具体要安 ...