Skip to content

Instantly share code, notes, and snippets.

@caub
Last active March 26, 2018 14:03
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 caub/253bd6de9e0638cca6d820b989aadf08 to your computer and use it in GitHub Desktop.
Save caub/253bd6de9e0638cca6d820b989aadf08 to your computer and use it in GitHub Desktop.
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
const TodoApp = ({ loading, error, data: { todos, refetch }, ...props }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
return (
<div {...props}>
<button onClick={() => refetch()}>Refresh</button>
<ul>{todos && todos.map(todo => <li key={todo.id}>{todo.text}</li>)}</ul>
</div>
);
};
export default graphql(gql`
{
todos {
id
text
}
}
`)(TodoApp);
// VS
import { Query } from 'react-apollo';
import gql from 'graphql-tag';
export default props => (
<Query
query={gql`
{
todos {
id
text
}
}
`}
>
{({ loading, error, data: { todos, refetch } }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
return (
<div {...props}>
<button onClick={() => refetch()}>Refresh</button>
<ul>{todos && todos.map(todo => <li key={todo.id}>{todo.text}</li>)}</ul>
</div>
);
}}
</Query>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment