Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovannibenussi/5ae26dcf9b7002f97fb4929b54dec4cf to your computer and use it in GitHub Desktop.
Save giovannibenussi/5ae26dcf9b7002f97fb4929b54dec4cf to your computer and use it in GitHub Desktop.
import React from 'react'
import { useQuery } from '@apollo/react-hooks'
import { gql } from 'apollo-boost'
const EXCHANGE_RATES = gql`
{
rates(currency: "USD") {
currency
rate
}
}
`
function ExchangeRates() {
const { loading, error, data } = useQuery(EXCHANGE_RATES)
if (loading) return <p>Loading...</p>
if (error) return <p>Error :(</p>
return data.rates.map(({ currency, rate }) => (
<ul key={currency}>
<li>
<strong>{currency}</strong>: {rate}
</li>
</ul>
))
}
export default ExchangeRates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment