The query to run. Must be a non-mutating query.
Optional params: UseExecuteQueryParams<U>Additional parameters to configure how the query is run.
const [insertTask] = useExecuteQuery(
'insert into tasks documents (:task)',
{
queryArguments: { task: { description: 'Buy milk' } },
},
)
const [executeQuery] = useExecuteQuery(
'insert into tasks documents (:task)',
{
queryArguments: { task: { author: 'Alice' } },
},
)
// Clicking the button will execute the query with query arguments
// `{ task: { author: 'Alice', description: 'Buy milk' } }`.
return <button
onClick={() => executeQuery({ task: { description: 'Buy milk' } })}
>Add Task</button>
Provides an execution function that can be used to run the given query.
This hook does not run the query immediately and does not set up a sync subscription. Use this hook for running mutating queries and ad-hoc queries in response to user actions. Be aware that mutations will not be synced to other peers unless you also set up a SyncSubscription for the same query, which can be done with a useQuery hook.
Query arguments can be supplied when setting up the hook and when calling the execution function. When query arguments contain the same key in both places, a shallow merge is performed, with the arguments passed to the execution function taking precedence. Below is an example of how to use this feature.
To avoid overly complex types, partial query arguments are only allowed on the execution function. This means that the query arguments passed when setting up the hook must be complete.
Errors that occur during query execution are stored in the
errorproperty of the return value and are reset on each subsequent execution. You can also provide anonErrorcallback in the hook parameters or when calling the execution function to handle errors as they occur.