Created
December 16, 2015 14:17
-
-
Save arunoda/423846f7b28af86f2cc6 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
var graphqlDemo = React.createClass({ | |
getInitialState() { | |
return {movies: []} | |
}, | |
componentDidMount() { | |
// query when we mount the view | |
client.query(` | |
{ | |
allFilms { | |
films { | |
title | |
} | |
} | |
} | |
`).then(result => { | |
this.setState({movies: result.allFilms.films}); | |
}).catch(error => { | |
this.setState({error}); | |
}); | |
}, | |
render: function() { | |
var {movies} = this.state; | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.title}> | |
"Star Wars" Movies | |
</Text> | |
{(movies.length > 0)? this.renderMovies(movies) : null} | |
</View> | |
); | |
}, | |
renderMovies(movies) { | |
return ( | |
<View> | |
{movies.map(movie => ( | |
<Text key={movie.title} style={styles.movies}> | |
{movie.title} | |
</Text> | |
))} | |
</View> | |
); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment