Created
June 11, 2020 16:02
-
-
Save alexandr-g/c314aaeadc31413a1145751a35819fce to your computer and use it in GitHub Desktop.
components/Users.js
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
// components/Users.js | |
import React from 'react' | |
import gql from 'graphql-tag' | |
import { useQuery } from '@apollo/react-hooks' | |
const UsersQuery = gql` | |
query Users { | |
users { | |
id | |
firstName | |
} | |
} | |
` | |
const Users = () => { | |
const { loading, error, data } = useQuery(UsersQuery) | |
if (loading) return 'loading users...' | |
if (error) return 'error while loading users' | |
return ( | |
<div> | |
<table> | |
<thead> | |
<tr> | |
<th>First Name</th> | |
</tr> | |
</thead> | |
<tbody> | |
{data.users.map((user) => ( | |
<tr key={user.id}> | |
<td>{user.firstName}</td> | |
</tr> | |
))} | |
</tbody> | |
</table> | |
</div> | |
) | |
} | |
export default Users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment