Created
June 25, 2019 10:05
-
-
Save chris001177/5d0f69be8ae7945d481dcb9852ed6361 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($limit: Int!) { | |
todos(limit: $limit) { | |
id | |
text | |
isDone | |
} | |
} | |
`; | |
const TodoList = ({ limit = 10 }) => { | |
<Query query={getTodos} variables={{ limit }}> | |
{({ fetching, data, error }) => { | |
if (fetching) { | |
return 'Loading...'; | |
} else if (error) { | |
return 'Oh no!'; | |
} | |
return ( | |
<ul> | |
{data.todos.map(({ id, text }) => ( | |
<li key={id}>{text}</li> | |
))} | |
</ul> | |
); | |
}} | |
</Query>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment