Created
June 25, 2019 10:17
-
-
Save chris001177/40aea5352ceb8831f0ce8e4a30fa8c98 to your computer and use it in GitHub Desktop.
This file contains 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 React from 'react'; | |
import { Query } from 'urql'; | |
const getTodos = ` | |
query GetTodos { | |
todos(limit: 10) { | |
id | |
text | |
isDone | |
} | |
} | |
`; | |
const TodoList = () => { | |
<Query query={getTodos}> | |
{({ executeQuery, data }) => { | |
if (!data) { | |
return null; | |
} | |
return ( | |
<div> | |
<ul> | |
{data.todos.map(({ id, text }) => ( | |
<li key={id}>{text}</li> | |
))} | |
</ul> | |
<button | |
onClick={() => executeQuery({ requestPolicy: 'network-only' })} | |
> | |
Refresh | |
</button> | |
</div> | |
); | |
}} | |
</Query>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment