Skip to content

8. makeMonitoredFetch

Naveen Mathew edited this page Mar 6, 2024 · 1 revision

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 enabled 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.

Options

makeMonitoredFetch has the following options available:

Required

  • fetchFn: any function that returns a Promise

Optional

  • onFetching: invoked with true when a fetch is inflight and false 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: if false, the fetch will be disabled. Defaults to true