@@ -77,7 +77,7 @@ function getNextState<TRequest extends Request>(
77
77
data : action . type === "success" ? action . data : state . data ,
78
78
response,
79
79
error : action . type === "error" ? action . error : undefined ,
80
- isLoading : action . type === "start" ? true : false ,
80
+ isLoading : action . type === "start" ,
81
81
// will be deleted
82
82
other : response ,
83
83
} ;
@@ -96,27 +96,27 @@ export function useResource<T extends Request>(
96
96
try {
97
97
return fn ( ...( requestParams || [ ] ) ) as Resource < Payload < T > , BodyData < T > > ;
98
98
} catch ( error ) {
99
- return undefined ;
99
+ return null ;
100
100
}
101
101
// eslint-disable-next-line react-hooks/exhaustive-deps
102
102
} , useDeepMemo ( [ fn , requestParams ] ) ) ;
103
103
const requestCache = useMemo ( ( ) => {
104
104
const filter = options ?. cacheFilter || RequestConfig . cacheFilter ;
105
+ const _cache = options ?. cache ?? RequestConfig . cache ;
106
+ if ( _cache == undefined ) {
107
+ return null ;
108
+ }
109
+
105
110
if ( filter && typeof filter === "function" ) {
106
111
if ( fnOptions && filter ( fnOptions ) ) {
107
- return options ?. cache ?? RequestConfig . cache ;
112
+ return _cache ;
108
113
}
109
- return undefined ;
110
114
}
111
115
112
- if (
113
- fnOptions ?. method === null ||
114
- fnOptions ?. method === undefined ||
115
- / ^ g e t $ / i. test ( fnOptions . method )
116
- ) {
117
- return options ?. cache ?? RequestConfig . cache ;
116
+ if ( fnOptions ?. method == null || / ^ g e t $ / i. test ( fnOptions . method ) ) {
117
+ return _cache ;
118
118
}
119
- return undefined ;
119
+ return null ;
120
120
} , [
121
121
RequestConfig . cache ,
122
122
RequestConfig . cacheFilter ,
@@ -130,14 +130,15 @@ export function useResource<T extends Request>(
130
130
fnOptions &&
131
131
( getStrByFn ( options ?. cacheKey , fnOptions ) ??
132
132
getStrByFn ( RequestConfig . cacheKey , fnOptions ) ) ) ||
133
- undefined
133
+ null
134
134
) ;
135
135
} , [ RequestConfig . cacheKey , fnOptions , options ?. cacheKey , requestCache ] ) ;
136
136
const cacheData = useMemo ( ( ) => {
137
137
if ( requestCache && cacheKey && typeof requestCache . get === "function" ) {
138
- return ( requestCache . get ( cacheKey ) as Payload < T , true > ) ?? undefined ;
138
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
139
+ return requestCache . get ( cacheKey ) as Payload < T , true > ;
139
140
}
140
- return undefined ;
141
+ return null ;
141
142
} , [ cacheKey , requestCache ] ) ;
142
143
143
144
const [ createRequest , { clear } ] = useRequest ( fn , {
@@ -146,7 +147,7 @@ export function useResource<T extends Request>(
146
147
instance : options ?. instance ,
147
148
} ) ;
148
149
const [ state , dispatch ] = useReducer ( getNextState , {
149
- data : cacheData ,
150
+ data : cacheData ?? undefined ,
150
151
isLoading : getDefaultStateLoading < T > ( requestParams , options ?. filter ) ,
151
152
...options ?. defaultState ,
152
153
} ) ;
@@ -204,8 +205,7 @@ export function useResource<T extends Request>(
204
205
const refreshRefFn = useRefFn ( refresh ) ;
205
206
206
207
useEffect ( ( ) => {
207
- // eslint-disable-next-line @typescript-eslint/no-empty-function
208
- let canceller : Canceler = ( ) => { } ;
208
+ let canceller : Canceler = ( ) => undefined ;
209
209
if ( requestParams ) {
210
210
const _c = refreshRefFn . current ( ) ;
211
211
if ( _c ) {
0 commit comments