Skip to content

Instantly share code, notes, and snippets.

@chris001177 chris001177/query.js
Created Jun 25, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.