Created
March 22, 2018 18:16
-
-
Save peggyrayzis/6577ed2646b45259840c290f544cbe71 to your computer and use it in GitHub Desktop.
RA 2.1 Query component
This file contains hidden or 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 "graphql-tag"; | |
const GET_TODOS = gql` | |
{ | |
todos { | |
id | |
type | |
} | |
} | |
`; | |
const Todos = () => ( | |
<Query query={GET_TODOS}> | |
{({ loading, error, data }) => { | |
if (loading) return <p>Loading...</p>; | |
if (error) return <p>Error :(</p>; | |
return data.todos.map(({ id, type }) => ( | |
<p key={id}>{type}</p> | |
)); | |
}} | |
</Query> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment