Skip to content

Instantly share code, notes, and snippets.

@marcaaron
Created August 12, 2018 18:58
Show Gist options
  • Save marcaaron/3ed365c0edb2e8aa660c790dd2e666c4 to your computer and use it in GitHub Desktop.
Save marcaaron/3ed365c0edb2e8aa660c790dd2e666c4 to your computer and use it in GitHub Desktop.
import React from "react";
import { Query } from "react-apollo";
import { gql } from "apollo-boost";
const MyComponent = props =>
<Query
query={MY_QUERY}>
{({ data, loading, error }) => {
if (loading) return 'Loading';
if (error) return `Error!: ${error}`;
const { things } = data;
return (
<div>
{things.map(({text, id}) => <p key={id}>{text}</p>)}
</div>
)
}}
</Query>
const MY_QUERY = gql`
query {
things{
id
text
}
}
`;
export default MyComponent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment