Skip to content

Instantly share code, notes, and snippets.

View josueayala27's full-sized avatar

Josué Ayala josueayala27

View GitHub Profile
@josueayala27
josueayala27 / useApi.ts
Last active December 27, 2024 14:09
useApi.ts is a Vue.js composable that provides a simple interface for interacting with an API. This composable encapsulates the logic of making HTTP requests, handling responses, errors, and loading states, and conveniently provides the API data for use in Vue components.
import type { FetchOptions } from 'ohmyfetch';
import { useApiMethod } from '@/enums/composables/useApi';
/**
* Custom hook that makes an HTTP request to the API endpoint.
*/
export async function useApi<T>(
path: string,
opts?: FetchOptions,
prefix = 'api',
@itzaks
itzaks / useAsyncState.ts
Created December 5, 2022 12:37
useAsyncState composable for fetching asyncdata in composables
import { Ref } from "vue"
interface AsyncStateOptions<T, O> {
transform?: (input: T) => O
}
interface AsyncStateReturnType<T> {
execute: () => Promise<void>,
refresh: () => Promise<void>,
pending: Ref<boolean>,
@josueayala27
josueayala27 / eslint_prettier_airbnb.md
Last active June 23, 2022 01:01
eslint_prettier_airbnb.md