Skip to content

Instantly share code, notes, and snippets.

@hwillson
Last active August 5, 2019 10:22
Show Gist options
  • Save hwillson/1b9974ef6122bf8d9a59994e0a615357 to your computer and use it in GitHub Desktop.
Save hwillson/1b9974ef6122bf8d9a59994e0a615357 to your computer and use it in GitHub Desktop.
React Apollo 3 - Multiple Mutations
function Message() {
const [saveMessage, { loading }] = useMutation(SAVE_MESSAGE);
const [deleteMessage] = useMutation(DELETE_MESSAGE);
const { data } = useQuery(GET_MESSAGE);
return (
<div>
<p>
{loading
? 'Loading ...'
: `Message: ${data && data.message ? data.message.content : ''}`}
</p>
<p>
<button onClick={() => saveMessage()}>Save</button>
<button onClick={() => deleteMessage()}>Delete</button>
</p>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment