Skip to content

Instantly share code, notes, and snippets.

@DanyF-github
Created January 8, 2021 10:41
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 DanyF-github/fd223caddb6bf9f6a5b025dc80e02321 to your computer and use it in GitHub Desktop.
Save DanyF-github/fd223caddb6bf9f6a5b025dc80e02321 to your computer and use it in GitHub Desktop.
// client/src/components/Homeworks/HomeworkList.tsx
import React from 'react';
import { useQuery } from '@apollo/client';
import { Link } from 'react-router-dom';
import { GET_HOMEWORKS } from '../../data/queries';
import { Homework } from '../../models';
const HomeworkList = () => {
// query the list of homeworks
const { data, loading, error } = useQuery(GET_HOMEWORKS);
// render the component with the retrieved homework
return (
<>
{loading && <p>Loading...</p>}
{error && <p>Error!</p>}
{data && (
<table>
<thead>
<tr>
<th>Identifier</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{data.homeworks.map((homework: Homework) => {
return (
<tr key={homework.uuid}>
<td>
<Link to={`/homeworks/${homework.uuid}/list`}>
{homework.uuid}
</Link>
</td>
<td>{homework.description}</td>
<td>
<Link to={`/homeworks/${homework.uuid}/upload`}>
Upload
</Link>
</td>
</tr>
)
})}
</tbody>
</table>
)}
</>
)
}
export default HomeworkList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment