I am developing a React form that's tied to a GraphQL mutation using the useMutation
of Apollo Client. On the server, I perform some validation and in case of errors, I reject the mutation. On the client-side, I use the error
object to receive the validation errors. My hook looks like this:
const [addDrone, { error }] = useMutation(ADD_DRONE)
So I unpack the error
object and present it to the user in a dialog to let him/her know what went wrong. After the user dismisses the dialog, I want to give the user a chance to fix the error so he/she can resubmit the form. This is where things get hairy. I want to clear the error
object when the user dismisses the dialog, but since this variable comes from the useMutation
hook there is no way for me to mutate or reset it. It looks like the useMutation
was designed to be fired once, and not used again.
So my question is, is there a way to "reset" a useMutation
hook back to it's original state?
@apollo/client 3.5.x
github.com/apollographql/apollo-client/issues/… – Shopping