Skip to content

Instantly share code, notes, and snippets.

@arunoda
Created December 16, 2015 14:17
Show Gist options
  • Save arunoda/423846f7b28af86f2cc6 to your computer and use it in GitHub Desktop.
Save arunoda/423846f7b28af86f2cc6 to your computer and use it in GitHub Desktop.
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