Skip to content

Instantly share code, notes, and snippets.

@peggyrayzis
Created March 22, 2018 18:16
Show Gist options
  • Save peggyrayzis/6577ed2646b45259840c290f544cbe71 to your computer and use it in GitHub Desktop.
Save peggyrayzis/6577ed2646b45259840c290f544cbe71 to your computer and use it in GitHub Desktop.
RA 2.1 Query component
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