import type { Inputs } from 'preact/hooks' import { useEffect } from 'preact/hooks' import type { AsyncCancel, AsyncState } from './index.js' import { useAsyncFn } from './index.js' export function useAsync( fn: () => Promise, inputs: Inputs = [], initialState: AsyncState = { loading: true }, ): AsyncState & { refresh: () => Promise } { const [state, callback] = useAsyncFn Promise>(fn, inputs, initialState) useEffect(() => { callback() }, [callback]) return { ...state, refresh: callback, } }