UNPKG

ruins

Version:

> [!IMPORTANT] > This is in beta. Not everything is ironed out and some modules might misbehave

24 lines (19 loc) 658 B
import { ref, onMounted } from "vue"; import { fetchy } from "../fetchy"; import type { TodoRes } from "../../../api/server/api/todos"; export function useTodos(structured = false) { const data = ref<TodoRes["data"]>(); const hasData = ref(true); onMounted(async () => { const getTodos = () => fetchy<TodoRes>("/todos"); const getStructuredTodos = () => fetchy<TodoRes>("/todos?structured=1"); const fetchTodos = structured ? getStructuredTodos : getTodos; const res = await fetchTodos(); if (!res.data) { hasData.value = false; return res.data; } data.value = res?.data; }); return { data, hasData }; }