8. makeMonitoredFetch
makeMonitoredFetch
wraps fetch functions and invokes onFetching
while it is fetching, onSuccess
when a fetch has successfully resolved and onError
if the fetch rejects. If the fetch is not enable
d then fetch is not executed.
makeMonitoredFetch
can be used to display a loading indicator when a fetch is inflight or in conjunction with useNetworkMode
to disable a fetch when there is no network connectivity.
makeMonitoredFetch
has the following options available:
-
fetchFn
: any function that returns aPromise
-
onFetching
: invoked withtrue
when a fetch is inflight andfalse
when a fetch has settled -
onSuccess
: invoked with the result of the fetch and the arguments to it upon resolving successfully -
onError
: invoked with the resulting error and the arguments to fetch upon rejecting -
enabled
: iffalse
, the fetch will be disabled. Defaults totrue