Skip to content

Instantly share code, notes, and snippets.

@barsumek
Last active November 22, 2018 13:30
Show Gist options
  • Save barsumek/c1d20e7487696e99dd37ec243f075dc2 to your computer and use it in GitHub Desktop.
Save barsumek/c1d20e7487696e99dd37ec243f075dc2 to your computer and use it in GitHub Desktop.
Detox your GraphQL: Pokemon Screen
class PokemonScreen extends Component {
render() {
const { loading, error, myPokemon } = this.props.data;
if (loading) {
return <ActivityIndicator />
}
if (error) {
return <ErrorScreen />
}
return (
<View style={styles.container}>
<Text style={styles.text}>Your favourite Pokemon:</Text>
<Text style={styles.text}>{`Name: ${myPokemon.name}`}</Text>
<Text style={styles.text}>{`Level: ${myPokemon.level === 30 ? 'MaxLvl' : myPokemon.level}`}</Text>
<Text style={styles.text}>{`Type: ${myPokemon.type}`}</Text>
<Text style={styles.text}>{`Caught: ${new Date(myPokemon.catchDate).toUTCString()}`}</Text>
</View>
);
}
}
export default graphql(gql`
query PokemonQuery {
myPokemon {
id
name
type
level
catchDate
}
}
`)(PokemonScreen);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment