Skip to content

Instantly share code, notes, and snippets.

@bw
Created September 6, 2017 01:24
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 bw/7f92797cfbfced23270f213936b7dd2a to your computer and use it in GitHub Desktop.
Save bw/7f92797cfbfced23270f213936b7dd2a to your computer and use it in GitHub Desktop.
// This is a functional version of code snippet #4:
// https://gist.github.com/bw/4d33f7f4d4cc096c51e923612338de94
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import Spinner from 'UI/components/Spinner';
import ContactItem from 'UI/components/items/ContactItem';
import getContactItemList from './ContactItemList.graphql';
const getContactItemList = ({
// Deconstruct the Apollo data object (given to us via props)
data: { user, loading },
}) => {
if (loading) return <Spinner />;
return (
<div className="contactList">
<h1>Hey, {user.name}!</h1>
<h2>These contacts need your action:</h2>
{user.contactsNeedingAction.map((contact, index) => (
<ContactItem contact={contact} key={index} />
))}
<h2>And here is everyone else:</h2>
{user.otherContacts.map((contact, index) => (
<ContactItem contact={contact} key={index} />
))}
</div>
);
};
// Use the react-apollo HOC (higher order component) to fetch our data.
export default graphql(ContactItemListQuery)(ContactItemList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment