[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 ...
随机推荐
- PHP检测输入数据是否合法常用的类(转)
<?php class Fun{ function isEmpty($val) { if (!is_string($val)) return false; //是否是字符串类型 if (empt ...
- VS中的路径宏
说明$(RemoteMachine)设置为“调试”属性页上“远程计算机”属性的值.有关更多信息,请参见更改用于 C/C++ 调试配置的项目设置.$(References)以分号分隔的引用列表被添加到项 ...
- selenium对浏览器属性操作的方法
最大化 方法一 //指明ChromeDriver路径 System.setProperty(Src_url_string.Chrome_Driver, Src_url_string.Driver_ad ...
- .NET中使用反射访问属性方法
.net所编写的程序集包含两个重要部分:IL(中间语言代码) 和metadata(元数据).我们编写的代码中不是有很多很多的类吗,类有很多很多的成员,在编译代码的时候,元数据表就根据代码把类的所有信息 ...
- Socket server
Socket server的使用方法(精华部分),仅供自用. class MyServer(socketserver.BaseRequestHandler): def handle(self): wh ...
- Svn install and use
1.安装服务 使用yum安装subversion,简单.不繁琐. 1 yum install -y subversion 2.创建版本库 1 2 mkidr /svn/obj ...
- MemCached总结三:PHP的memcached管理接口
在Web系统中应用MemCached缓存技术,必须使用客户端API(PHP)进行访问,这样才能将用户请求的动态数据,缓存到memcached服务器中,来减少对数据库的访问压力.PHP中提供了用于内存缓 ...
- Laravel5 开启Debug
Laravel默认没有开启Debug,打开需要两步: .env文件中设置APP_DEBUG=true: 把Laravel服务重启一下(摸索出来的). 这只是开启了基本的调试模式,如果需要看更详细的调试 ...
- ANN:DNN结构演进History—LSTM_NN
前言 语音识别和动作识别(Action.Activities) 等一些时序问题,通过微分方式可以视为模式识别方法中的变长模式识别问题.语音识别的基元为音素.音节,字母和句子模式是在时间轴上的变长序列 ...
- 基于SLIC分割的特征点检测
一:pipeLIne (1):基于模型的pose估计综述: 对于一个3D模型,可以投影到平面,得到不同的位姿,而pose识别是利用所见的2.5D图像,来估计模型,并同时识别出位姿. 3D模型投影时注意 ...