@@ -102,22 +102,25 @@ const createContinuablePromise = <T>(
102
102
103
103
type Options = Parameters < typeof useStore > [ 0 ] & {
104
104
delay ?: number
105
+ unstable_defaultUse ?: boolean
105
106
unstable_promiseStatus ?: boolean
106
107
}
107
108
108
- export function useAtomValue < Value > (
109
+ export function useAtomValue < Value , O extends Options = Options > (
109
110
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
117
117
118
118
export 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 || { }
121
124
const store = useStore ( options )
122
125
123
126
const [ [ valueFromReducer , storeFromReducer , atomFromReducer ] , rerender ] =
@@ -174,7 +177,7 @@ export function useAtomValue<Value>(atom: Atom<Value>, options?: Options) {
174
177
if ( promiseStatus ) {
175
178
attachPromiseStatus ( promise )
176
179
}
177
- return use ( promise )
180
+ return unstable_defaultUse ? use ( promise ) : promise
178
181
}
179
182
return value as Awaited < Value >
180
183
}
0 commit comments