-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddresses.js
More file actions
34 lines (29 loc) · 690 Bytes
/
Copy pathAddresses.js
File metadata and controls
34 lines (29 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from "react";
import { gql } from "apollo-boost";
import { useQuery } from "@apollo/react-hooks";
const GET_ADDRESSES_QUERY = gql`
query getAllAddresses {
getAddresses {
id
houseNumber
postcode
}
}
`;
export const Addresses = () => {
const { loading, error, data } = useQuery(GET_ADDRESSES_QUERY);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
return (
<div>
<h2>List of addresses</h2>
<ul>
{data.getAddresses.map(({ id, postcode, houseNumber }, index) => (
<li key={index}>
{houseNumber}, {postcode}
</li>
))}
</ul>
</div>
);
};