Created
April 10, 2021 13:25
-
-
Save ilxanlar/9b8d099944394dbbc773005f58790c95 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 { useQuery } from 'react-query' | |
const fetchTodos = async () => { | |
// Fetch todos from the API | |
} | |
function Todos() { | |
const { data, isError, isLoading } = useQuery('todos', fetchTodos) | |
if (isError) { | |
return <p>Failed to load todos.</p> | |
} | |
if (isLoading) { | |
return <p>Loading todos...</p> | |
} | |
return ( | |
<> | |
<InsertTodo /> | |
<ul> | |
{data.map(todo => ( | |
<li key={todo.id}> | |
{todo.text} | |
</li> | |
))} | |
</ul> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment