import { ref } from "vue";

export function useAsync(promise) {
    const data = ref(null);
    const isLoading = ref(true);
    const error = ref(null);

    promise
        .then(result => {
            data.value = result;
        })
        .catch(err => {
            error.value = err;
        })
        .finally(() => {
            isLoading.value = false;
        });

    return { data, isLoading, error };
}
