Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created October 1, 2018 03:42
Show Gist options
  • Save JeffML/f321278c0101a15fb8353f070ac7b798 to your computer and use it in GitHub Desktop.
Save JeffML/f321278c0101a15fb8353f070ac7b798 to your computer and use it in GitHub Desktop.
import React from "react"
import { Query } from "react-apollo";
import gql from "graphql-tag";
const ExchangeRates = () => (
<Query
query={gql`
{
rates(currency: "USD") {
currency
rate
name
}
}
`}
>
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
return data.rates.map(({ currency, rate, name }) => (
<div key={currency}>
<p>{`${currency}: ${rate}(${name})`}</p>
</div>
));
}}
</Query>
);
export default ExchangeRates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment