1- import type { Ref , ShallowRef , UnwrapRef } from 'vue'
1+ import type { MaybeRef , Ref , ShallowRef , UnwrapRef } from 'vue'
22import { noop , promiseTimeout , until } from '@vueuse/shared'
3- import { ref as deepRef , shallowRef } from 'vue'
3+ import { ref as deepRef , shallowRef , toValue } from 'vue'
44
55export interface UseAsyncStateReturnBase < Data , Params extends any [ ] , Shallow extends boolean > {
66 state : Shallow extends true ? Ref < Data > : Ref < UnwrapRef < Data > >
@@ -81,7 +81,7 @@ export interface UseAsyncStateOptions<Shallow extends boolean, D = any> {
8181 */
8282export function useAsyncState < Data , Params extends any [ ] = any [ ] , Shallow extends boolean = true > (
8383 promise : Promise < Data > | ( ( ...args : Params ) => Promise < Data > ) ,
84- initialState : Data ,
84+ initialState : MaybeRef < Data > ,
8585 options ?: UseAsyncStateOptions < Shallow , Data > ,
8686) : UseAsyncStateReturn < Data , Params , Shallow > {
8787 const {
@@ -100,7 +100,7 @@ export function useAsyncState<Data, Params extends any[] = any[], Shallow extend
100100
101101 async function execute ( delay = 0 , ...args : any [ ] ) {
102102 if ( resetOnExecute )
103- state . value = initialState
103+ state . value = toValue ( initialState )
104104 error . value = undefined
105105 isReady . value = false
106106 isLoading . value = true
0 commit comments