import { ref, onBeforeMount } from 'vue'; import type { Ref } from 'vue'; export default function useDataFetcherList(fetchFunction: (req: Request) => Promise, req: Request): { responseData: Ref, loading: Ref, error: Ref, fetchData: () => Promise } { // Declare reactive variables using the ref function const responseData: Ref = ref(null) const loading: Ref = ref(false) const error: Ref = ref(null) // Define the fetchData function const fetchData = async () => { loading.value = true try { // Execute the fetchFunction with the given request parameter const response = await fetchFunction(req) // Assign the response to the responseData variable responseData.value = response } catch (err: any) { error.value = err.message || 'An error occurred.' } finally { loading.value = false } } onBeforeMount(() => { fetchData() }) return { responseData, loading, error, fetchData }; }