Instantly share code, notes, and snippets.

Embed
What would you like to do?
Querying for data from AWS AppSync
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { API, graphqlOperation } from 'aws-amplify'
import { listRestaurants } from './graphql/queries.js'
class App extends Component {
state = { restaurants: [] }
async componentDidMount() {
try {
const apiData = await API.graphql(graphqlOperation(listRestaurants))
const restaurants = apiData.data.listRestaurants.items
this.setState({ restaurants })
} catch (err) {
console.log('error: ', err)
}
}
render() {
return (
<div className="App">
{
this.state.restaurants.map((rest, i) => (
<div style={styles.item}>
<p style={styles.name}>{rest.name}</p>
<p style={styles.description}>{rest.description}</p>
</div>
))
}
</div>
);
}
}
const styles = {
item: {
padding: 10,
borderBottom: '2px solid #ddd'
},
name: { fontSize: 22 },
description: { color: 'rgba(0, 0, 0, .45)' }
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment