import { ref, onBeforeMount } from 'vue'; import type { Ref } from 'vue'; // import type { RouteLocationNormalizedLoaded } from 'vue-router'; export default function useDataFetcherFind(fetchFunction: Function, request: Request, mapFunction?: Function): { responseData: Ref, loading: Ref, error: Ref, fetchData: () => Promise } { const responseData: Ref = ref(null) const loading: Ref = ref(true) const error: Ref = ref(null) const fetchData = async () => { loading.value = true try { const response = await fetchFunction(request) if (mapFunction) { responseData.value = mapFunction(response) } else { responseData.value = response } } catch (err: any) { error.value = err.message || 'An error occurred.' } finally { loading.value = false } } onBeforeMount(() => { fetchData() }) return { responseData, loading, error, fetchData }; }