UseMutation

  • hook returns an array
  • first element contains the result of the mutation
  • use refetchQueries parameters in [UseMutation] hook to keep cache in sync
    • drawback being that the query is always rerun with any updates
const ALL_PERSONS = gql`
query {
allPersons {
name
phone
id
}
}
`
const PersonForm = (props) => {
// ...
const [ createPerson ] = useMutation(CREATE_PERSON, {
refetchQueries: [ { query: ALL_PERSONS } ]
})

Apollo Docs: useMutation