Created
May 1, 2020 17:42
-
-
Save giovannibenussi/5ae26dcf9b7002f97fb4929b54dec4cf to your computer and use it in GitHub Desktop.
This file contains 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 { 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