Skip to content

Commit

Permalink
if error, don't break Pagination
Browse files Browse the repository at this point in the history
If there is an error e.g a network error we should return your Error component as to not break the rest of the component e.g `const count = data.itemsConnection.aggregate.count`

OR
`const count = !error ? data.itemsConnection.aggregate.count : props`
  • Loading branch information
dunatron committed Mar 3, 2019
1 parent 815f22f commit 67401e5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion finished-application/frontend/components/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Head from 'next/head';
import Link from 'next/link';
import PaginationStyles from './styles/PaginationStyles';
import { perPage } from '../config';
import Error from './ErrorMessage';

const PAGINATION_QUERY = gql`
query PAGINATION_QUERY {
Expand All @@ -20,7 +21,8 @@ const Pagination = props => (
<Query query={PAGINATION_QUERY}>
{({ data, loading, error }) => {
if (loading) return <p>Loading...</p>;
const count = data.itemsConnection.aggregate.count;
if (error) return <Error error={error} />;
const count = data.itemsConnection.aggregate.count
const pages = Math.ceil(count / perPage);
const page = props.page;
return (
Expand Down

0 comments on commit 67401e5

Please sign in to comment.