Skip to content

Instantly share code, notes, and snippets.

@nakajo2011
Last active May 3, 2021 08:31
Show Gist options
  • Save nakajo2011/a67d2b0efa01234d088768bc5fcd9844 to your computer and use it in GitHub Desktop.
Save nakajo2011/a67d2b0efa01234d088768bc5fcd9844 to your computer and use it in GitHub Desktop.
Apollo Client/Getting Started sample2
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