@@ -126,8 +126,7 @@ const useAsync = (arg1, arg2) => {
126126
127127const parseResponse = ( accept , json ) => res => {
128128 if ( ! res . ok ) return Promise . reject ( res )
129- if ( json === false ) return res
130- if ( json === true || accept === "application/json" ) return res . json ( )
129+ if ( json === true || ( json !== false && accept === "application/json" ) ) return res . json ( )
131130 return res
132131}
133132
@@ -136,13 +135,17 @@ const useAsyncFetch = (input, init, { defer, json, ...options } = {}) => {
136135 const headers = input . headers || ( init && init . headers ) || { }
137136 const accept = headers [ "Accept" ] || headers [ "accept" ] || ( headers . get && headers . get ( "accept" ) )
138137 const doFetch = ( input , init ) => globalScope . fetch ( input , init ) . then ( parseResponse ( accept , json ) )
139- const isDefer = defer === true || ~ [ "POST" , "PUT" , "PATCH" , "DELETE" ] . indexOf ( method )
140- const fn = defer === false || ! isDefer ? "promiseFn" : "deferFn"
138+ const isDefer =
139+ defer === true || ( defer !== false && ~ [ "POST" , "PUT" , "PATCH" , "DELETE" ] . indexOf ( method ) )
140+ const fn = isDefer ? "deferFn" : "promiseFn"
141141 const state = useAsync ( {
142142 ...options ,
143143 [ fn ] : useCallback (
144- ( _ , props , ctrl ) => doFetch ( input , { signal : ctrl ? ctrl . signal : props . signal , ...init } ) ,
145- [ JSON . stringify ( input ) , JSON . stringify ( init ) ]
144+ isDefer
145+ ? ( [ override ] , _ , { signal } ) =>
146+ doFetch ( input , { signal, ...( typeof override === "function" ? override ( init ) : init ) } )
147+ : ( _ , { signal } ) => doFetch ( input , { signal, ...init } ) ,
148+ [ isDefer , JSON . stringify ( input ) , JSON . stringify ( init ) ]
146149 ) ,
147150 } )
148151 useDebugValue ( state , ( { counter, status } ) => `[${ counter } ] ${ status } ` )
0 commit comments