Closed idkjs closed 4 years ago
It's number 2: "you might be breaking the rules of hooks". In the error it says "Hooks can only be called inside of the body of a function component", but here you're using a hook in the body of a plain function.
And to answer how the two things are different, one is a hook and one is a method on the client (both do essentially the same thing). The hook has other args you can pass to it like onCompleted
for some rare use-case, but ultimately, both executing the mutation that comes out of the hook and calling the method on the client return a promise. You would use the resolution of the promise to know when it is completed. I've never really had a use-case for useMutation
, it feels like burden to me. I always do client.mutate
.
Also, please note you are not actually executing your mutation in your hook example. Please check out the apollo docs on how to use useMutation
: https://www.apollographql.com/docs/react/data/mutations/
Thank you for taking the time to educate me, brother. Peace to you.
I am trying to use
onCompleted
onuseMutation
. Maybe this is equivalent to some other method in the library?This compiles but doesnt not look right and cause an
invalid hook call
error.error:
Being called like this since its the only way i can get it to compile:
Thank you in advance! Super work here!
Also, how is the above function different from the following which works but doesnt have
onCompleted
as an option?