Skip to content

Instantly share code, notes, and snippets.

@chris001177
Created June 25, 2019 10:05
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 chris001177/5d0f69be8ae7945d481dcb9852ed6361 to your computer and use it in GitHub Desktop.
Save chris001177/5d0f69be8ae7945d481dcb9852ed6361 to your computer and use it in GitHub Desktop.
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