-
-
Save ericwooley/aa4d78cd26643165a5b422d0cc716c96 to your computer and use it in GitHub Desktop.
todoList-with-errors
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 { | |
useMyListsQuery, | |
useCreateListMutation, | |
} from '@the-wooley-devbox/graphql-sdk'; | |
export const TodoList = () => { | |
const [createList] = useCreateListMutation(); | |
const { data, loading, error, refetch } = useMyListsQuery({ ssr: false }); | |
if (loading) return <h3>Loading...</h3>; | |
if (error) | |
return ( | |
<h3> | |
Uh oh, something went wrong! | |
<hr /> | |
<button onClick={() => refetch()}>Try again</button> | |
</h3> | |
); | |
return ( | |
<div> | |
<h3> | |
My Lists ({`${data.myLists.length}`}){' '} | |
<button | |
onClick={() => { | |
createList({ | |
variables: { | |
name: | |
prompt('What do you want to name your list?') || | |
'Untitled List', | |
}, | |
}).then(() => refetch()); | |
}} | |
> | |
+ | |
</button> | |
: | |
</h3> | |
{data.myLists.length === 0 && ( | |
<h4>Looks like you don't have any lists yet.</h4> | |
)} | |
{data.myLists.map((list) => ( | |
<div key={list.id}> | |
<h4>{list.name}</h4> | |
{list.items.map((todo) => ( | |
<div key={todo.id}> | |
<input type="checkbox" checked={todo.done} /> | |
| |
<strong>{todo.name}</strong> | |
</div> | |
))} | |
</div> | |
))} | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment