commandstring. For example,
useExec('echo', ['Raycast'])is the same as
commandis not a constant but a variable, for example with
process.cwd(). Except for spaces, no escaping/quoting is needed.
shelloption must be used if the command uses shell-specific features (for example,
||), as opposed to being a simple file followed by its arguments.
fileis the path to the file to execute.
argumentsis an array of strings to pass as arguments to the file.
commandis the string to execute.
options.shellis a boolean or a string to tell whether to run the command inside of a shell or not. If
/bin/sh. A different shell can be specified as a string. The shell should understand the
options.stripFinalNewlineis a boolean to tell the hook to strip the final newline character from the output. By default, it will.
options.cwdis a string to specify the current working directory of the child process. By default, it will be
options.envis a key-value pairs to set as the environment of the child process. It will extend automatically from
options.encodingis a string to specify the character encoding used to decode the
stderroutput. If set to
stderrwill be a
Bufferinstead of a string.
options.inputis a string or a Buffer to write to the
stdinof the file.
options.timeoutis a number. If greater than
0, the parent will send the signal
SIGTERMif the child runs longer than timeout milliseconds.
options.parseOutputis a function that accepts the output of the child process as an argument and returns the data the hooks will return - see ParseExecOutputHandler. By default, the hook will return
options.keepPreviousDatais 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.initialDatais the initial value of the state if there aren't any in the Cache yet.
options.executeis 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.onErroris 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.onDatais a function called when an execution succeeds.
options.onWillExecuteis a function called when an execution will start.
revalidateis a method to manually call the function with the same arguments again.
mutateis 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.
trueand 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).
optimisticUpdatefunction to mutate the data in order to reflect the change introduced by the asynchronous update.
rollbackOnErrorfunction 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.