Created
July 14, 2023 01:55
-
-
Save willie-hung/71c405d5820831b44e7f6919c6cc11aa to your computer and use it in GitHub Desktop.
post_9
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 "@tanstack/react-query"; | |
import axios from "axios"; | |
interface Todo { | |
id: number; | |
title: string; | |
userId: number; | |
completed: boolean; | |
} | |
const useTodos = () => { | |
const fetchTodos = () => | |
axios | |
.get<Todo[]>("https://jsonplaceholder.typicode.com/todos") | |
.then((res) => res.data); | |
return useQuery<Todo[], Error>({ | |
queryKey: ["todos"], | |
queryFn: fetchTodos, | |
}); | |
}; | |
export default useTodos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment