Skip to content

Instantly share code, notes, and snippets.

@alexandr-g
Created June 11, 2020 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandr-g/c314aaeadc31413a1145751a35819fce to your computer and use it in GitHub Desktop.
Save alexandr-g/c314aaeadc31413a1145751a35819fce to your computer and use it in GitHub Desktop.
components/Users.js
// 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