Skip to content

Instantly share code, notes, and snippets.

@dabit3
Created May 13, 2019 18:44
Show Gist options
  • Save dabit3/29a5aa7e719c29269ceb9ebf18faf475 to your computer and use it in GitHub Desktop.
Save dabit3/29a5aa7e719c29269ceb9ebf18faf475 to your computer and use it in GitHub Desktop.
Game of thrones app build with GraphQL & React Native
import React, {useState, useEffect} from 'react';
import {StyleSheet, Text, View, Image} from 'react-native';
import { API, graphqlOperation } from 'aws-amplify'
const query = `
query listCharacters {
listCharacters {
items {
id name description avatar
}
}
}
`
function App() {
const [characters, setCharacters] = useState([])
async function fetchCharacters() {
try {
const gotData = await API.graphql(graphqlOperation(query))
setCharacters(gotData.data.listCharacters.items)
} catch (err) {
console.log({ err })
}
}
useEffect(() => {
fetchCharacters()
}, [])
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
{
characters.map((c, i) => (
<View>
<Image source={{uri: c.avatar}} />
<Text>{c.name}</Text>
<Text>{c.description}</Text>
</View>
))
}
</View>
);
}
export default App
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment