Last active
September 11, 2020 18:56
-
-
Save cant89/72bf7f1b806e8d4b8d8dee9103194f47 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 { useQuery } from 'react-query'; | |
export const useFetchFirstTodo = () => { | |
const { data, error, isLoading } = useQuery("fetchFirstTodo", fetchFirstTodo); | |
// -> dispatch and action | |
// -> manipulate the response before sending back to component | |
// -> call another api | |
// -> whatever makes sense for you to put here... | |
return { data, error, isLoading } | |
} | |
const Todo = () => { | |
const { data, error, isLoading } = useFetchFirstTodo(); | |
if (error) { | |
return `Error: ${error} `; | |
} | |
if (isLoading) { | |
return "Loading..."; | |
} | |
if (data) { | |
const { title, completed } = data; | |
return `${title} is ${!completed && "not "} completed`; | |
} | |
return null; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment