BugQuery.tsx

 1import * as React from 'react';
 2import { RouteComponentProps } from 'react-router-dom';
 3
 4import CircularProgress from '@material-ui/core/CircularProgress';
 5
 6import NotFoundPage from '../notfound/NotFoundPage';
 7
 8import Bug from './Bug';
 9import { useGetBugQuery } from './BugQuery.generated';
10
11type Props = RouteComponentProps<{
12  id: string;
13}>;
14
15const BugQuery: React.FC<Props> = ({ match }: Props) => {
16  const { loading, error, data } = useGetBugQuery({
17    variables: { id: match.params.id },
18  });
19  if (loading) return <CircularProgress />;
20  if (!data?.repository?.bug) return <NotFoundPage />;
21  if (error) return <p>Error: {error}</p>;
22  return <Bug bug={data.repository.bug} />;
23};
24
25export default BugQuery;