[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 ...
随机推荐
- ACdream 1154 Lowbit Sum (数位DP)
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...
- 为了世界的和平~一起上caioj~~~!
打Call~打Call~打Call~~~!!! 世界毁灭了你在哪???不要犹豫,快去caioj!!! 无比优质的oj,未来大牛的明智之选----就是caioj~~~
- Linux - 网络相关指令
系统时间与开关机 查看系统时间 date 查看硬件日期 hwclock 学习Linux不必全部指令都会,只要记住主要常用的几个就可以了.--MK 关机命令 shutdown init reboot p ...
- [xPlugin] smartupload jsp图片上传
URL:http://www.cnblogs.com/ISeeYouBlogs/p/jsp.html 1.要实现图片上传,首先需要一个组件,这里我用的是smartupload.jar可以到这里下载ht ...
- 【优化算法】遗传算法GA求解混合流水车间调度问题(附C++代码)
00 前言 各位读者大家好,好久没有介绍算法的推文了,感觉愧对了读者们热爱学习的心灵.于是,今天我们带来了一个神奇的优化算法--遗传算法! 它的优点包括但不限于: 遗传算法对所求解的优化问题没有太多的 ...
- Kaggle爆文:一个框架解决几乎所有机器学习问题
上周一个叫 Abhishek Thakur 的数据科学家,在他的 Linkedin 发表了一篇文章 Approaching (Almost) Any Machine Learning Proble ...
- .net几种文件下载的方法
.Net文件下载方式.... 之前在写上传文件.下载文件的时候,发现Response对象里面有好几种下载文件的方式,之后自己亲自实践了这几种方法,记录下以便以后复习... WriteFile文件下载 ...
- 第二次作业&熟悉使用工具
GIT地址 我的地址 GIT用户名 995020892w 学号后五位 81105 博客地址 我的博客 作业链接 第二次作业 一.环境配置过程 安装vs2017 因为以前学习C#相关 ...
- sql多表关联
inner join(等值连接) 只返回两个表中联结字段相等的行 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有 ...
- 01--数据结构——动态链表(C++)
数据结构——动态链表(C++) 定义一个节点: [cpp] view plain copy print? #include <iostream> using namespace s ...