Skip to content

Instantly share code, notes, and snippets.

@JeffML
Last active October 1, 2018 03:16
Show Gist options
  • Save JeffML/b0a99e42b7ef4e80db6ecc783213604c to your computer and use it in GitHub Desktop.
Save JeffML/b0a99e42b7ef4e80db6ecc783213604c to your computer and use it in GitHub Desktop.
import React from "react";
import { Query } from 'react-apollo';
import gql from "graphql-tag";
const query = gql`{
currencyOfInterest @client
}`
const ExchangeSelector = ({data: {rates}}) => (
<Query query={query}>
{({ data, client }) => {
const { currencyOfInterest} = data;
const currRate = rates && rates.find(rate => rate.currency === currencyOfInterest)
const { rate, name } = currRate? currRate : {rate: 0, name: ""}
return (
<div>
<input name="currencyOfInterest" value={currencyOfInterest}
onChange={(evt) => client.writeData({ data: { currencyOfInterest: evt.target.value } })}></input>
&nbsp;&nbsp;
<input name="rate" readOnly value={rate}></input>
&nbsp;&nbsp;
<input name="name" readOnly value={name}></input>
</div>
)
}}
</Query>)
export default ExchangeSelector;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment