Created
March 29, 2019 15:33
-
-
Save kamiljozwik/be7441a6be8bbf18c309e832daef7888 to your computer and use it in GitHub Desktop.
This file contains 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
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import { withAuthenticator } from 'aws-amplify-react' | |
import { API, graphqlOperation } from 'aws-amplify' // dodajemy komunikację z API na froncie | |
// Pytamy API o listę wszystkich notatek | |
const ListNotes = ` | |
query { | |
listNotes { | |
items { | |
id title description importance | |
} | |
} | |
} | |
` | |
class App extends Component { | |
state = { notes: [] } // listę notatek trzymamy w stanie komponentu | |
async componentDidMount () { | |
const noteDate = await API.graphql(graphqlOperation(ListNotes)) // pobieramy notatki | |
this.setState({ notes: noteData.data.listNotes.items }) // i zapisujemy do stanu | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<h1 className="App-title">Welcome to React</h1> | |
</header> | |
{ | |
this.state.notes.map((note, i)) => ( // wyświetlamy wszystkie notatki | |
<div> | |
<h3>{note.title}</h3> | |
<p>{note.description}</p> | |
<p>{note.importance}</p> | |
</div> | |
)) | |
} | |
</div> | |
); | |
} | |
} | |
export default withAuthenticator(App, { includeGreetings: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment