@@ -102,22 +102,25 @@ const createContinuablePromise = <T>(
102102
103103type Options = Parameters < typeof useStore > [ 0 ] & {
104104 delay ?: number
105+ unstable_defaultUse ?: boolean
105106 unstable_promiseStatus ?: boolean
106107}
107108
108- export function useAtomValue < Value > (
109+ export function useAtomValue < Value , O extends Options = Options > (
109110 atom : Atom < Value > ,
110- options ?: Options ,
111- ) : Awaited < Value >
112-
113- export function useAtomValue < AtomType extends Atom < unknown > > (
114- atom : AtomType ,
115- options ?: Options ,
116- ) : Awaited < ExtractAtomValue < AtomType > >
111+ options ?: O ,
112+ ) : O extends { unstable_defaultUse : true } ? Awaited < Value > : Value
113+ export function useAtomValue < Value , O extends Options = Options > (
114+ atom : Atom < Value > ,
115+ options ?: O ,
116+ ) : O extends { unstable_defaultUse : true } ? Awaited < Value > : Value
117117
118118export function useAtomValue < Value > ( atom : Atom < Value > , options ?: Options ) {
119- const { delay, unstable_promiseStatus : promiseStatus = ! React . use } =
120- options || { }
119+ const {
120+ delay,
121+ unstable_promiseStatus : promiseStatus = ! React . use ,
122+ unstable_defaultUse = true ,
123+ } = options || { }
121124 const store = useStore ( options )
122125
123126 const [ [ valueFromReducer , storeFromReducer , atomFromReducer ] , rerender ] =
@@ -174,7 +177,7 @@ export function useAtomValue<Value>(atom: Atom<Value>, options?: Options) {
174177 if ( promiseStatus ) {
175178 attachPromiseStatus ( promise )
176179 }
177- return use ( promise )
180+ return unstable_defaultUse ? use ( promise ) : promise
178181 }
179182 return value as Awaited < Value >
180183}
0 commit comments