Skip to content

Instantly share code, notes, and snippets.

@peterj
Created December 28, 2017 23:00
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 peterj/fd761e8a396f38583eecd4c62578f1e2 to your computer and use it in GitHub Desktop.
Save peterj/fd761e8a396f38583eecd4c62578f1e2 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import Link from './Link';
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
const ALL_LINKS_QUERY = gql`
query AllLinksQuery {
allLinks {
id
url
description
hash
}
}
`;
class LinkList extends Component {
render() {
if (this.props.allLinksQuery && this.props.allLinksQuery.loading) {
return <div>Loading ...</div>;
}
if (this.props.allLinksQuery && this.props.allLinksQuery.error) {
return <div>Error occurred</div>;
}
const allLinks = this.props.allLinksQuery.allLinks;
if (allLinks.length === 0) {
return <div>No links...</div>;
}
return (
<div>
{allLinks.map(link => <Link key={link.id} link={link} />)}
</div>
);
}
}
export default graphql(ALL_LINKS_QUERY, { name: 'allLinksQuery' })(LinkList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment