Created
November 4, 2018 14:28
-
-
Save igeligel/8254e23da33b8259cab7f3cae53deb1c 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 gql from 'graphql-tag'; | |
import { Query } from 'react-apollo'; | |
const GET_DOGS = gql` | |
{ | |
dogs { | |
id | |
breed | |
} | |
} | |
`; | |
const Dogs = ({ onDogSelected }) => ( | |
<Query query={GET_DOGS}> | |
{({ loading, error, data }) => { | |
if (loading) return 'Loading...'; | |
if (error) return `Error! ${error.message}`; | |
return ( | |
<select name="dog" onChange={onDogSelected}> | |
{data.dogs.map(dog => ( | |
<option key={dog.id} value={dog.breed}> | |
{dog.breed} | |
</option> | |
))} | |
</select> | |
); | |
}} | |
</Query> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment