Last active
October 1, 2018 03:16
-
-
Save JeffML/b0a99e42b7ef4e80db6ecc783213604c to your computer and use it in GitHub Desktop.
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 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> | |
| |
<input name="rate" readOnly value={rate}></input> | |
| |
<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