Last active
          May 3, 2021 08:31 
        
      - 
      
- 
        Save nakajo2011/a67d2b0efa01234d088768bc5fcd9844 to your computer and use it in GitHub Desktop. 
    Apollo Client/Getting Started sample2
  
        
  
    
      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 {gql, useQuery} from '@apollo/client'; | |
| const EXCHANGE_RATES = gql` | |
| query GetExchangeRates { | |
| rates(currency: "USD") { | |
| currency | |
| rate | |
| } | |
| } | |
| `; | |
| interface RateData { | |
| currency: string, | |
| rate: string, | |
| } | |
| 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((data: RateData) => ( | |
| <div key={data.currency}> | |
| <p> | |
| {data.currency}: {data.rate} | |
| </p> | |
| </div> | |
| )); | |
| } | |
| export default ExchangeRates; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment