Created
December 30, 2018 17:38
-
-
Save tomodutch/1fe4d04d8ca108f12844f9f3ba39bef9 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 * as React from "react"; | |
import { GetTodos } from "./queries/__generated__/GetTodos"; | |
import { GetTodosQuery, getTodosQuery } from "./queries/todos"; | |
export const Todos = () => ( | |
<GetTodosQuery query={getTodosQuery}> | |
{({ loading, error, data }) => { | |
if (loading) { | |
return <span>loading</span>; | |
} | |
if (error) { | |
return <span>error</span>; | |
} | |
return renderTodos(data); | |
}} | |
</GetTodosQuery> | |
); | |
function renderTodos(data: GetTodos | undefined) { | |
if (!data || !data.allTodos) { | |
return <span>No todos found</span>; | |
} | |
return ( | |
<ul> | |
{data.allTodos.map(todo => { | |
if (todo) { | |
return <li key={todo.id}>{todo.title}</li>; | |
} | |
return; | |
})} | |
</ul> | |
); | |
} | |
export default Todos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment