Skip to content

Instantly share code, notes, and snippets.

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