Skip to content

Instantly share code, notes, and snippets.

@willie-hung
Created July 14, 2023 01:55
Show Gist options
  • Save willie-hung/71c405d5820831b44e7f6919c6cc11aa to your computer and use it in GitHub Desktop.
Save willie-hung/71c405d5820831b44e7f6919c6cc11aa to your computer and use it in GitHub Desktop.
post_9
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