import {useMutation} from 'blitz'
import updateProject from 'app/projects/mutations/updateProject'
function (props) {
const [updateProjectMutation] = useMutation(updateProject)
return (
<Formik
onSubmit={async values => {
try {
const project = await updateProjectMutation(values)
} catch (error) {
alert('Error saving project')
}
}}>
{/* ... */}
</Formik>
)
}For more examples and use cases, see the mutation usage documentation.
const [
invoke,
{
status,
isIdle,
isLoading,
isSuccess,
isError,
data,
error,
reset
}
] = useMutation(mutationResolver, {
onMutate,
onSuccess,
onError,
onSettled,
throwOnError,
useErrorBoundary,
})
const promise = invoke(inputArguments, {
onSuccess,
onSettled,
onError,
throwOnError,
})mutationResolver: A Blitz mutation resolveroptionsonMutate: Function(inputArguments) => Promise | snapshotValueonError and onSettled functions in the event of a mutation failure
and can be useful for rolling back optimistic updates.onSuccess: Function(data, inputArguments) => Promise | undefinedmutate-level onSuccess handler (if it is defined)onError: Function(err, inputArguments, onMutateValue) => Promise | undefinedmutate-level onError handler (if it is defined)onSettled: Function(data, error, inputArguments, onMutateValue) => Promise | undefinedmutate-level onSettled handler (if it is defined)throwOnErrortruefalse if failed mutations should not re-throw errors
from the mutation function to the mutate function.useErrorBoundary[invoke, mutationExtras]
invoke: Function(inputArguments, { onSuccess, onSettled, onError, throwOnError }) => PromiseinputArguments: anymutationResolver.useMutation hook.useMutation-level options.mutationExtras: Objectstatus: Stringidle initial status prior to the mutation function executing.loading if the mutation is currently executing.error if the last mutation attempt resulted in an error.success if the last mutation attempt was successful.isIdle, isLoading, isSuccess, isError: boolean variables derived
from statusdata: undefined | Anyundefinederror: null | Errorreset: Function() => void