File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export interface FetchProps<TData = any, TError = Error> {
37
37
| { [ type : string ] : ( res : TData ) => Promise < any > } ;
38
38
fetchFunction ?: ( url : string , options : RequestInit ) => Promise < any > ;
39
39
onDataChange ?: ( newData : TData , data : TData ) => any ;
40
+ onResponseChange ?: ( response : Response ) => any ;
40
41
onChange ?: ( result : FetchResult < TData , TError > ) => void ;
41
42
deps ?: [ any ] ;
42
43
}
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ function useFetch(props) {
145
145
promises . current . splice ( 0 , index + 1 ) ;
146
146
}
147
147
148
- const { onChange, onDataChange } = props ;
148
+ const { onChange, onDataChange, onResponseChange } = props ;
149
149
150
150
let data = undefined ;
151
151
if (
@@ -159,6 +159,14 @@ function useFetch(props) {
159
159
) ;
160
160
}
161
161
162
+ if (
163
+ nextState . response &&
164
+ nextState . response !== state . response &&
165
+ isFunction ( onResponseChange )
166
+ ) {
167
+ data = onResponseChange ( nextState . response ) ;
168
+ }
169
+
162
170
if ( isFunction ( onChange ) ) {
163
171
// Always call onChange even if unmounted. Useful for `POST` requests with a redirect
164
172
onChange ( {
You can’t perform that action at this time.
0 commit comments