1
- import type { Ref , ShallowRef , UnwrapRef } from 'vue'
1
+ import type { MaybeRef , Ref , ShallowRef , UnwrapRef } from 'vue'
2
2
import { noop , promiseTimeout , until } from '@vueuse/shared'
3
- import { ref as deepRef , shallowRef } from 'vue'
3
+ import { ref as deepRef , shallowRef , toValue } from 'vue'
4
4
5
5
export interface UseAsyncStateReturnBase < Data , Params extends any [ ] , Shallow extends boolean > {
6
6
state : Shallow extends true ? Ref < Data > : Ref < UnwrapRef < Data > >
@@ -81,7 +81,7 @@ export interface UseAsyncStateOptions<Shallow extends boolean, D = any> {
81
81
*/
82
82
export function useAsyncState < Data , Params extends any [ ] = any [ ] , Shallow extends boolean = true > (
83
83
promise : Promise < Data > | ( ( ...args : Params ) => Promise < Data > ) ,
84
- initialState : Data ,
84
+ initialState : MaybeRef < Data > ,
85
85
options ?: UseAsyncStateOptions < Shallow , Data > ,
86
86
) : UseAsyncStateReturn < Data , Params , Shallow > {
87
87
const {
@@ -100,7 +100,7 @@ export function useAsyncState<Data, Params extends any[] = any[], Shallow extend
100
100
101
101
async function execute ( delay = 0 , ...args : any [ ] ) {
102
102
if ( resetOnExecute )
103
- state . value = initialState
103
+ state . value = toValue ( initialState )
104
104
error . value = undefined
105
105
isReady . value = false
106
106
isLoading . value = true
0 commit comments