Skip to content

Instantly share code, notes, and snippets.

@ilxanlar
Created April 10, 2021 13:25
Show Gist options
  • Save ilxanlar/9b8d099944394dbbc773005f58790c95 to your computer and use it in GitHub Desktop.
Save ilxanlar/9b8d099944394dbbc773005f58790c95 to your computer and use it in GitHub Desktop.
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