Created
August 12, 2018 18:58
-
-
Save marcaaron/3ed365c0edb2e8aa660c790dd2e666c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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