Created
February 18, 2024 08:02
-
-
Save dmateos/f11dcc86652a6086bdc54e03faecc51b 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
| import React from 'react'; | |
| import logo from './logo.svg'; | |
| import './App.css'; | |
| import { useState, useEffect } from 'react'; | |
| import { Amplify } from 'aws-amplify'; | |
| import { generateClient } from 'aws-amplify/api'; | |
| import { listPersons } from './graphql/queries'; | |
| import { Person } from "./API"; | |
| Amplify.configure({ | |
| API: { | |
| GraphQL: { | |
| endpoint: 'xxx', | |
| region: 'ap-southeeast-2', | |
| defaultAuthMode: 'apiKey', | |
| apiKey: 'xxx', | |
| } | |
| } | |
| }); | |
| function PersonRenderer() { | |
| const [persons, setPersons] = useState<(Person | null)[]>([]); | |
| const client = generateClient(); | |
| useEffect(() => { | |
| fetchPersons(); | |
| }, []); | |
| async function fetchPersons() { | |
| try { | |
| const data = await client.graphql({ query: listPersons }); | |
| setPersons(data.data.listPersons!); | |
| } catch (error) { | |
| console.error(error); | |
| } | |
| } | |
| return ( | |
| <div> | |
| { | |
| persons.map((person) => ( | |
| <p key={person?.PersonID}> | |
| <div> {person?.FirstName} </div> | |
| <div> {person?.LastName} </div> | |
| <div> {person?.Address} </div> | |
| </p> | |
| )) | |
| } | |
| </div> | |
| ); | |
| } | |
| function App() { | |
| return ( | |
| <div className="App"> | |
| <header className="App-header"> | |
| <img src={logo} className="App-logo" alt="logo" /> | |
| </header> | |
| <div> | |
| <PersonRenderer /> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment