url
is the string representation of the URL to fetch.options.parseResponse
is a function that accepts the Response as an argument and returns the data the hooks will return. But default, the hook will return response.json()
if the response has a JSON Content-Type
header or response.text()
otherwise.options.keepPreviousData
is a boolean to tell the hook to keep the previous results instead of returning the initial value if there aren't any in the cache for the new arguments. This is particularly useful when used for data for a List to avoid flickering.options.initialData
is the initial value of the state if there aren't any in the Cache yet.options.abortable
is a reference to an AbortController
to cancel a previous call when triggering a new one.options.execute
is a boolean to indicate whether to actually execute the function or not. This is useful for cases where one of the function's arguments depends on something that might not be available right away (for example, depends on some user inputs). Because React requires every hook to be defined on the render, this flag enables you to define the hook right away but wait until you have all the arguments ready to execute the function.options.onError
is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry.options.onData
is a function called when an execution succeeds.options.onWillExecute
is a function called when an execution will start.revalidate
is a method to manually call the function with the same arguments again.mutate
is a method to wrap an asynchronous update and gives some control over how the useFetch
's data should be updated while the update is going through. By default, the data will be revalidated (eg. the function will be called again) after the update is done. See Mutation and Optimistic Updates for more information.keepPreviousData
to true
and the hook will keep the latest fetched data if the cache is empty for the new arguments (initial data -> fetched data -> arguments change -> fetched data).optimisticUpdate
function to mutate the data in order to reflect the change introduced by the asynchronous update.rollbackOnError
function to mutate back the data if the asynchronous update fails. If not specified, the data will be automatically rolled back to its previous value (before the optimistic update).useFetch
's data should be updated while the update is going through.