Use urql's useMutation Hook in React Native to Execute a Mutation

Share this video with your friends

Send Tweet

We'll use the useMutation hook to expose the mutation function. Call the mutation function to add a story to bookmarks when the user taps the bookmark button.

Then we will ensure the bookmarkId is returned in the mutation request value so its gets updates in the cache (and so also the UI).

During this process, we'll generate some types for the useMutation to ensure we are passing in the correct data.

Resources:

  • Bookmark emoji: https://emojipedia.org/bookmark/
  • urql mutations docs: https://formidable.com/open-source/urql/docs/basics/react-preact/#mutations

Checkpoint: Add a story to bookmarks