Last active
March 26, 2018 14:03
-
-
Save caub/253bd6de9e0638cca6d820b989aadf08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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