Skip to content
Snippets Groups Projects
Commit 3fe33c4c authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: allow useAsyncFunction use with predefined error ref

This is helpful if multiple operations should use the same error object.
parent b87b0292
No related branches found
No related tags found
No related merge requests found
......@@ -36,9 +36,13 @@ export const useId = (() => {
}
})()
export function useAsyncFunction<F extends (...args: never[]) => Promise<unknown>>(fn: F) {
type UseAsyncFunctionOptions = { error?: Ref<Error | undefined> }
export function useAsyncFunction<F extends (...args: never[]) => Promise<unknown>>(
fn: F,
options: UseAsyncFunctionOptions | undefined = undefined,
) {
const isProcessing = ref(false)
const error = ref<Error | undefined>()
const error = options?.error ?? ref<Error | undefined>()
async function wrapper(...args: Parameters<F>): Promise<Awaited<ReturnType<F>>> {
isProcessing.value = true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment